samsondav / rihanna

Rihanna is a high performance postgres-backed job queue for Elixir
MIT License
439 stars 49 forks source link

Job scheduling #20

Closed slashdotdash closed 6 years ago

slashdotdash commented 6 years ago

Schedule jobs to run at a DateTime or in a number of milliseconds.

Schedule at a DateTime:

Rihanna.schedule(
  {IO, :puts, ["Hello"]},
  at: DateTime.from_naive!(~N[2018-07-01 12:00:00], "Etc/UTC")
)

Schedule in one hour:

Rihanna.schedule({IO, :puts, ["Hello"]}, in: :timer.hours(1))

Jobs scheduled for later execution will run shortly after their scheduled date, but there is no guarantee they will run at exactly their due date as this will depend on your configured poll interval and what other jobs are being processed.

Upgrading

Scheduled jobs requires a database upgrade to add due_at column to the Rihanna jobs table.

The easiest way to upgrade the database is with Ecto. Run mix ecto.gen.migration upgrade_rihanna_jobs and make your migration look like this:

defmodule MyApp.UpgradeRihannaJobs do
  use Rihanna.Migration.Upgrade
end

Now you can run mix ecto.migrate.