View Source Oban.Plugins.Cron (Oban v2.11.0)
Periodically enqueue jobs through CRON based scheduling.
Using the Plugin
Schedule various jobs using {expr, worker} and {expr, worker, opts} syntaxes:
config :my_app, Oban,
plugins: [
{Oban.Plugins.Cron,
crontab: [
{"* * * * *", MyApp.MinuteWorker},
{"0 * * * *", MyApp.HourlyWorker, args: %{custom: "arg"}},
{"0 0 * * *", MyApp.DailyWorker, max_attempts: 1},
{"0 12 * * MON", MyApp.MondayWorker, queue: :scheduled, tags: ["mondays"]},
{"@daily", MyApp.AnotherDailyWorker}
]}
]🌟 This plugin only loads the crontab statically, at boot time. To configure cron schedules
dynamically at runtime, across your entire cluster, see the DynamicCron plugin in Oban
Pro.
Options
:crontab— a list of cron expressions that enqueue jobs on a periodic basis. See Periodic Jobs in the Oban module docs for syntax and details.:timezone— which timezone to use when scheduling cron jobs. To use a timezone other than the default of "Etc/UTC" you must have a timezone database like tzdata installed and configured.
Instrumenting with Telemetry
The Oban.Plugins.Cron plugin adds the following metadata to the [:oban, :plugin, :stop] event:
- :jobs - a list of jobs that were inserted into the database
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Link to this section Types
Specs
cron_input() :: {binary(), module()} | {binary(), module(), [Oban.Job.option()]}
Specs
option() ::
{:conf, Oban.Config.t()}
| {:name, GenServer.name()}
| {:crontab, [cron_input()]}
| {:timezone, Calendar.time_zone()}
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Specs
start_link([option()]) :: GenServer.on_start()