I want to create a quantum elixir job and control the time it is executed. I started with this:
Quantum.Job.new(task: fn -> IO.puts "Hello!" end)
but it throws this error:
** (KeyError) key :run_strategy not found in: [task: #Function<20.99386804/0 in :erl_eval.expr/5>]
(elixir) lib/keyword.ex:371: Keyword.fetch!/2
(quantum) lib/quantum/job.ex:58: Quantum.Job.new/1
I really don't understand the run_strategy setting and it's possible values.
Does somebody knows how to create a quantum job using the struct of Quantum.Job.new or something similar?
NOTE: the cron is already working using this:
config :sopitas, Sopitas.Scheduler,
jobs: [
# Every minute
{"@minutely", {Sopitas.Admin.FixtureController, :update_cron, []}},
{"@minutely", {Sopitas.Admin.StandingController, :update_cron, []}},
{"@daily", {Sopitas.Admin.LeagueController, :update_cron, []}},
]
but the point is to change the time the cron is executed, that's why I decided to create it using Quantum.Job.new
The solution was easier than I thought. The Quantum documentation says:
I changed the tuples by lists, so I can name each job. I can fetch them by their names and change their schedules:
I created a function which handles the jobs:
I call that function as follows: