# `Oban.Lifeline`
[🔗](https://github.com/oban-bg/oban/blob/v2.24.2/lib/oban/lifeline.ex#L1)

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`.

> #### 🌟 Oban Pro's Lifeline {: .info}
>
> 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
> [`Oban.Pro.Lifeline`](https://oban.pro/docs/pro/Oban.Pro.Lifeline.html).

## Using the Plugin

Rescue orphaned jobs that are still `executing` after the default of 1 hour:

    config :my_app, Oban,
      lifeline: Oban.Lifeline,
      ...

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

    config :my_app, Oban,
      lifeline: [rescue_after: {5, :minutes}],
      ...

## Options

* `:interval` — the time between rescue attempts, as either an integer number of milliseconds
  or an `Oban.Period` tuple like `{1, :minute}`. The default is `60_000ms`.

* `:rescue_after` — the maximum amount of time a job may execute before being rescued, as either
  an integer number of milliseconds or an `Oban.Period` tuple like `{1, :hour}`. 1 hour
  by default, and rescuing is performed once a minute.

## Instrumenting with Telemetry

The `Oban.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`

When a run can't reach the database both lists are empty and an `:error` is added to the
metadata, as described in `Oban.Telemetry`.

_Note: jobs only include `id`, `queue`, `state` fields._

# `option`

```elixir
@type option() ::
  Oban.Plugin.option()
  | {:interval, Oban.Period.t()}
  | {:rescue_after, Oban.Period.t()}
```

