Hi Guys. This is first time using oban for scheduling periodic job
I want to send emails to all subscribed user at the last day of month and save result to database.
in config.exs
{Oban.Plugins.Cron,
crontab: [
{"55 23 30 4,6,9,11 *",MyApp.EmailWorker, args: %{type: "emails"}},
{"55 23 31 1,3,5,7,8,10,12 *", MyApp.EmailWorker,
args: %{type: "emails"}},
{"55 23 28 2 *", MyApp.EmailWorker, args: %{type: "emails"}}
]}
In EmailWorker.ex
defmodule MyApp.EmailWorker do
use Oban.Worker, queue: :emails, max_attempts: 3
@impl Worker
def perform(oban_job) do
Subscribers.all()
|> Enum.map(fn subscriber ->
content = "some content"
send_email(subscriber, content) |> save_to_database()
end)
end
end
- This will insert cron job at last day of the month and will do the job?
- How can I test if it is scheduled correctly?