Write tests to assert ExScheduler.Worker
periodic behaviour in test/ex_scheduler/worker_test.exs
.
Cron-like job scheduler in few lines of elixir code.
Inspired in this answer by José Valim.
Added cron syntax, with extended support for seconds.
def deps do
[
{:ex_scheduler, "~> 0.1.0"}
]
end
Add ExScheduler.Worker to your supervision tree:
children = [
{ExScheduler.Worker, jobs}
]
And the jobs configuration:
defp jobs() do
[
%{cron: "* * * * * *", module: Example, function: :hello, args: ["world"]},
%{cron: "* * * * * *", module: PerformExample},
]
end
If using Phoenix Framework, you should pull this configuration from config.exs.
- When the function is omitted,
perform/0
function is called. - When
args
are ommited, the function is called with no attributes. - Cron expressions are evaluated over UTC time.