Instead of providing one global Quantum GenServer, every app has to provide its own Scheduler in V2. (Like for example Ecto.Repo)
This allows Umbrella Projects etc. to maintain their own quantum configuration without interfering with other apps.
1: create Scheduler:
defmodule YourApp.Scheduler do
use Quantum.Scheduler,
otp_app: :your_app
end2: add Scheduler to your supervision tree:
defmodule YourApp.Application do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# This is the new line
worker(YourApp.Scheduler, [])
]
opts = [strategy: :one_for_one, name: YourApp.Supervisor]
Supervisor.start_link(children, opts)
end
endThe configuration notations have been cleaned up. Those are the existing notations:
{:cron, "* * * * *"}(Tuple of:cron, String) - Expression without second support{:extended, "* * * * * *"}(Tuple of:extended, String) - Expression with second support"* * * * *"(Any String) - Expression without second support
{Module, :func, [args]}- Standard Way of specifying Tasksfn -> :some_anon_func end}- Used for simple short tasks
config :your_app, YourApp.Scheduler,
jobs: [
# Named Tuple Explicit Form
{NAME, [schedule: CONFIG_SCHEDULE_NOTATION, task: CONFIG_TASK_NOTATION, OTHER_FIELDS]},
# Named Keyword Explicit Form
[name: NAME, schedule: CONFIG_SCHEDULE_NOTATION, task: CONFIG_TASK_NOTATION, OTHER_FIELDS],
# Unnamed Explicit Form
[schedule: CONFIG_SCHEDULE_NOTATION, task: CONFIG_TASK_NOTATION, OTHER_FIELDS],
# Short Form
{CONFIG_SCHEDULE_NOTATION, CONFIG_TASK_NOTATION},
]Only the Crontab.CronExpression struct is supported. Use the sigil ~e[EXPRESSION] for an easy way to define the schedule.
{Module, :func, [args]}- Standard Way of specifying Tasksfn -> :some_anon_func end}- Used for simple short tasks
The job struct should not be manipulated by hand. Please use the factory YourApp.Scheduler.new_job (Quantum.Scheduler.new_job/1) to create a new instance and the setters in Quantum.Job to manipulate the job.
The setter do not normalize values as in v1. The correct type has to be provided.
Instead of a nodes list, a run strategy can be provided. The nodes list is not supported anymore.