# `PhoenixReplay.Session.Finalizer`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/session/finalizer.ex#L1)

Completes a finished recording and saves it with retries.

Runs inside a task started by `PhoenixReplay.Session.Monitor`, so
redaction and the backoff sleeps block only that task. The events still
in the buffer are redacted with the session's `PhoenixReplay.Redactor`
and joined to the chunks already flushed to storage, see `complete/3`.
If that fails, nothing is saved.
Attempts and backoff come from the `:persist` configuration; the delay
grows linearly with the attempt number.

# `complete`

```elixir
@spec complete(PhoenixReplay.Recording.t(), PhoenixReplay.Config.t(), keyword()) ::
  {:ok, PhoenixReplay.Recording.t()} | {:error, term()}
```

Completes a buffered session's recording, for saving it or for showing
it while it runs: redacts the events still in the buffer and puts the
chunks already flushed to storage, which were redacted when they were
written, before them.

Takes the `:progress` option of
`PhoenixReplay.Redactor.redact_recording/3`.

# `finish`

```elixir
@spec finish(PhoenixReplay.Recording.t(), PhoenixReplay.Config.t()) ::
  {:ok, PhoenixReplay.Recording.t()} | {:error, term()}
```

Saves the buffered `recording` with `persist/2`, then closes its buffer
and emits `[:phoenix_replay, :recording, :persisted]` or `:failed`.

The task does this itself, so a session is finished even if the monitor
that started the task restarts meanwhile.

# `persist`

```elixir
@spec persist(PhoenixReplay.Recording.t(), PhoenixReplay.Config.t()) ::
  {:ok, PhoenixReplay.Recording.t()} | {:error, term()}
```

Completes and saves the buffered `recording`, retrying the save until it
succeeds or attempts run out. Returns the saved recording.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
