View Source Oban.Plugins.Lifeline (Oban v2.14.0)

Naively transition jobs stuck executing back to available.

The Lifeline plugin periodically rescues orphaned jobs, i.e. jobs that are stuck in the executing state because the node was shut down before the job could finish. Rescuing is purely based on time, rather than any heuristic about the job's expected execution time or whether the node is still alive.

If an executing job has exhausted all attempts, the Lifeline plugin will mark it discarded rather than available.

🌟 DynamicLifeline

This plugin may transition jobs that are genuinely executing and cause duplicate execution. For more accurate rescuing or to rescue jobs that have exhausted retry attempts see the DynamicLifeline plugin in Oban Pro.

using-the-plugin

Using the Plugin

Rescue orphaned jobs that are still executing after the default of 60 minutes:

config :my_app, Oban,
  plugins: [Oban.Plugins.Lifeline],
  ...

Override the default period to rescue orphans after a more aggressive period of 5 minutes:

config :my_app, Oban,
  plugins: [{Oban.Plugins.Lifeline, rescue_after: :timer.minutes(5)}],
  ...

options

Options

  • :interval — the number of milliseconds between rescue attempts. The default is 60_000ms.

  • :rescue_after — the maximum amount of time, in milliseconds, that a job may execute before being rescued. 60 minutes by default, and rescuing is performed once a minute.

instrumenting-with-telemetry

Instrumenting with Telemetry

The Oban.Plugins.Lifeline plugin adds the following metadata to the [:oban, :plugin, :stop] event:

  • :rescued_jobs — a list of jobs transitioned back to available

  • :discarded_jobs — a list of jobs transitioned to discarded

Note: jobs only include id, queue, state, and worker fields.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Link to this section Types

@type option() ::
  Oban.Plugin.option() | {:interval, timeout()} | {:rescue_after, pos_integer()}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.