Deleting old events from the outbox, so domain_events doesn't grow forever.
DDD.Outbox.Retention.prune(MyApp.Repo, older_than_days: 30)
# => {:ok, %{deleted: 1204}}Or from the command line: mix vic.outbox.prune --older-than-days 30. To prune on a schedule,
give the supervisor retention: [older_than_days: 30] (see DDD.Supervisor) or call
prune/2 from your own scheduler.
What is deleted, once it is older than the limit:
- events that were published (every handler succeeded or rejected them), together with their delivery records
- dead letters that were resolved (discarded or replayed)
What is never deleted: events still waiting, events being retried, and dead letters nobody has resolved.
Pruning is a choice with a cost. A projection's rebuild/0 replays the events in this
table; once the old ones are gone, a rebuild can only rebuild from what is left. Prune after
the longest history you are willing to rebuild from, or archive the table first.
Summary
Functions
Delete old events. Options
Functions
@spec prune(module(), keyword()) :: {:ok, %{deleted: non_neg_integer()}}
Delete old events. Options:
:older_than_days- (required) how old, in days, an event must be. There is no default: deleting is not something to do by accident.:batch- rows deleted per statement (default 5000), so a big backlog doesn't hold long locks
Returns {:ok, %{deleted: count}}.