Oban Crontab : make sure that the module exist and is a job
Closed this issue · 1 comments
Is your feature request related to a problem? Please describe.
This is related to an issue we just had etalab/transport-site#3558. We refactored some code, renamed a job and forgot to update it in our runtime.exs
therefore the module was not found at boot time.
Describe the Solution You'd Like
Would it be possible to declare the Oban crontab configuration is a safer way, ensuring that modules exist and are Oban.Job
s like perform_job/3
does?
Maybe we should register jobs through a function to validate arguments?
config :my_app, Oban,
plugins: [
{Oban.Plugins.Cron,
crontab: [
Oban.cron({"* * * * *", MyApp.MinuteWorker}),
Oban.cron({"0 * * * *", MyApp.HourlyWorker, args: %{custom: "arg"}}),
Oban.cron({"0 0 * * *", MyApp.DailyWorker, max_attempts: 1}),
Oban.cron({"0 12 * * MON", MyApp.MondayWorker, queue: :scheduled, tags: ["mondays"]}),
Oban.cron({"@daily", MyApp.AnotherDailyWorker})
]}
]
The Cron plugin already validates the existence of a module and that it's a worker. In your case, the issue appears to be that the crontab isn't configured outside of production.
The standard advice is to define the same config for all environments, including test
, so tests automatically validate it. Eliminate the conditional and configure the queues and plugins regardless; only set testing: :manual
for the test
environment.