rihanna v0.5.2 Rihanna.Job behaviour

A behaviour for Rihanna jobs.

You must implement Rihanna.Job.perform/1 in your job, and it must return one of the following values:

  • :ok
  • {:ok, result}
  • :error
  • {:error, reason}

You can define your job like the example below:

defmodule MyApp.MyJob do
  @behaviour Rihanna.Job

  # NOTE: `perform/1` is a required callback. It takes exactly one argument. To
  # pass multiple arguments, wrap them in a list and destructure in the
  # function head as in this example
  def perform([arg1, arg2]) do
    success? = do_some_work(arg1, arg2)

    if success? do
      # job completed successfully
      :ok
    else
      # job execution failed
      {:error, :failed}
    end
  end
end

Link to this section Summary

Functions

The name of the jobs table

Link to this section Types

Link to this type reason()
reason() :: any()
Link to this type result()
result() :: any()
Link to this type t()
t() :: %Rihanna.Job{
  enqueued_at: term(),
  fail_reason: term(),
  failed_at: term(),
  id: term(),
  term: term()
}

Link to this section Functions

Link to this function lock(pg, n, exclude_ids)

The name of the jobs table.

Link to this section Callbacks

Link to this callback perform(arg)
perform(arg :: any()) :: :ok | {:ok, result()} | :error | {:error, reason()}