roger v2.4.0 Roger.Partition.Worker.Callback behaviour View Source

Provides hooks into the job execution lifecycle.

Roger can be configured with callback modules for the job worker, which invokes functions on various places in the job’s life cycle.

config :roger,
  callbacks: MyWorkerModule

In this scenario, the mentioned MyWorkerModule needs to use Roger.Partition.Worker.Callback:

defmodule MyWorkerModule do
  use Roger.Partition.Worker.Callback
end

In this worker module, you can implement the functions before_run/2, after_run/2, on_error/4, on_cancel/2 and on_buried/2 to respond to job events.

Link to this section Summary

Callbacks

Executed just after the job has ran

Executed just before the job is going to run

Executed when the job has failed its retry sequence

Executed when the job was cancelled

Executed when a job has exited with an error

Link to this section Callbacks

Link to this callback after_run(arg0, arg1, any, any) View Source (optional)
after_run(String.t(), Roger.Job.t(), any(), any()) :: any()

Executed just after the job has ran

Link to this callback before_run(arg0, arg1) View Source (optional)
before_run(String.t(), Roger.Job.t()) :: any()

Executed just before the job is going to run

Link to this callback on_buried(partition_id, job, any, any, any) View Source (optional)
on_buried(
  partition_id :: String.t(),
  job :: Roger.Job.t(),
  any(),
  any(),
  any()
) :: any()

Executed when the job has failed its retry sequence

Retryable jobs are retried in an exponential fashion. When the job has failed the retry sequence, e.g. it failed every time, it is put in a special queue called “buried”. Upon placement in this queue, this callback gets executed.

Link to this callback on_cancel(arg0, arg1) View Source (optional)
on_cancel(String.t(), Roger.Job.t()) :: any()

Executed when the job was cancelled

A job can be cancelled either when it is still in the queue or while it is executing. The cancel callback will be only executed once.

Link to this callback on_error(arg0, arg1, {}, any, any) View Source (optional)
on_error(String.t(), Roger.Job.t(), {atom(), String.t()}, any(), any()) ::
  any()

Executed when a job has exited with an error