Baton.Retention (Baton v0.1.0)

Copy Markdown View Source

Deletes Baton's own rows once the Oban job they belong to is gone.

Baton's tables (workflow_nodes, workflow_step_stats, workflow_debug_logs, workflow_completions) carry no foreign key to oban_jobs — Oban owns that table and prunes it on its own schedule. Without cleanup, every workflow ever run would leave permanent rows here.

This module piggybacks on Oban's Pruner: a row is considered dead once its backing oban_jobs row has been pruned. Baton.Plugin calls delete_orphans/2 on its sweep when pruning is enabled.

Safety

A node/stat row is deleted only when its own job is gone, and Oban only prunes jobs that are already terminal (completed/cancelled/discarded) and past its max_age. As long as that max_age exceeds your longest workflow's runtime — which Baton already requires for correct dependency gating — this never removes data a still-running workflow depends on.

Deletes are bounded by limit per call so a large backlog is worked down across several sweeps rather than in one long transaction.

Summary

Functions

Delete up to limit orphaned rows from each Baton table. Returns a map of table => deleted_count.

Functions

delete_orphans(repo, limit)

@spec delete_orphans(module(), pos_integer()) :: %{
  required(atom()) => non_neg_integer()
}

Delete up to limit orphaned rows from each Baton table. Returns a map of table => deleted_count.