# `Keksdose.Retention`
[🔗](https://github.com/io2/keksdose/blob/v0.4.1/lib/keksdose/retention.ex#L1)

Periodic deletion of consent records older than `retention_days`.

Opt-in: the package does **not** start this GenServer on its own. Add it to
your host application's supervision tree:

    children = [
      MyApp.Repo,
      # ... other children ...
      {Keksdose.Retention, retention_days: 395}
    ]

Or via config + Application:

    # config/config.exs
    config :keksdose,
      repo: MyApp.Repo,
      retention_days: 395,
      retention_check_interval_ms: :timer.hours(24)

    # MyApp.Application
    children = [MyApp.Repo, Keksdose.Retention]

Setting `retention_days: nil` (or omitting the config) disables purging;
the GenServer starts but never deletes. Useful if you want the process in
your tree before deciding on a retention policy.

Emits `[:keksdose, :retention, :purged]` on every successful run
(including zero-deletion runs).

## Performance note

Purges run as a single `DELETE WHERE inserted_at < cutoff`. On tables with
millions of rows-to-delete (e.g. enabling retention for the first time
after years of accumulation) the initial run may briefly lock the table
and bloat WAL on PostgreSQL. For that scenario, do a manual batched
cleanup with `DELETE ... LIMIT 10_000` before relying on the GenServer for
steady-state housekeeping.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `purge_now`

Run a purge immediately (synchronous). Returns `{:ok, deleted_count}` or
`{:error, reason}`. Useful for tests and ad-hoc operator runs.

# `start_link`

---

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