felix-starman

felix-starman

Livebook as a replacement for scheduled ETL?

So I have been writing Elixir for the better part of a decade now and using Livebook to solve small problems for myself for daily operations but I am trying to encourage our data analyst to investigate it as well instead of recreating our ecto queries in SQL and then running them in bigquery which seems like a waste.

A lot of these need to be nightly scheduled queries, but I don’t want to require them to have to write oban jobs if they want just get started at doing something.

Has anyone come up with a way to run a livebook on a schedule without user input?

Marked As Solved

jonatanklosko

jonatanklosko

Creator of Livebook

Hey @felix-starman, we plan to explore scheduled execution in the future, most likely in relation to Livebook Teams, tracked in Allow scheduled execution of multi-session apps · Issue #2091 · livebook-dev/livebook · GitHub.

That said, you should be able to create a notebook or app that runs code periodically. Here’s a quick idea:

<!-- livebook:{"app_settings":{"slug":"cron"}} -->

# Cron

```elixir
Mix.install([
  {:kino, "~> 0.12.3"},
  {:quantum, "~> 3.5"}
])
```

## Section

```elixir
defmodule Scheduler do
  use Quantum, otp_app: :scheduler
end

defmodule Tasks do
  require Logger

  def hello() do
    Logger.info("Hello #{DateTime.utc_now()}")
  end
end

Application.put_env(:scheduler, Scheduler,
  jobs: [
    {"* * * * *", {Tasks, :hello, []}}
  ]
)

Kino.start_child(Scheduler)
```

In the task you could even do RPC into a remote node.

You can deploy that notebook as an app, so it is more “permanent”, and you most likely want it to run on a cloud instance. There are already options to deploy with Docker, and we are working on Livebook Teams, where you will be able to deploy an app like this into your infrastructure with a single click.

These are just some quick notes, this is definitely open to ideas and future features : )

Also Liked

jonatanklosko

jonatanklosko

Creator of Livebook

Notebooks are isolated, so there is no way to share modules between them.

In the notebook you could do this:

button = Kino.Control.button("Run hello") |> Kino.render()
Kino.listen(button, fn _ -> Tasks.hello() end)

if Kino.Hub.app_info().type != :none do
  Kino.start_child(Scheduler)
end

So there is an explicit button to run the task on demand, and the cron is only started when the notebook runs as an app (as opposed to just being open and edited). This way you can reuse the same notebook for both manual and scheduled. And this way it should be fine to use a single notebook that defines all the tasks, each of them can be run with a button, and there’s a single cron config for all of them.

If you want to define tasks in separate notebooks and have a single notebook with a cron, then the modules would need to be a dependency or perhaps they would live in a production node that the notebook RPCs into (which may be the way to go anyway, so that you can use all the application code/setup, but that depends on the exact use case).

larshei

larshei

I am very much interested in exactly this usecase as well.

Currently running a lot of “Pipelines” (ETL) in Azure, which are … not my personal favourite.

Looking to replace those with scripts or livebooks. We already have Livebook Teams available but unfortunately haven’t gotten to use it much within the team as of yet.

I think instead of scheduling we run a RabbitMQ consumer in each livebook and use messages to trigger runs.

That way, the livebook can be deployed permanently and only does work when required.

josevalim

josevalim

Creator of Elixir

Latest Livebook supports running a proxy/web server too, so you could also listen to HTTP requests and start workflows.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement