StatifierPersistence.Retention (StatifierPersistence v0.18.0)

Copy Markdown View Source

Clearing what a finished execution leaves behind (ADR-0016).

An execution that has ended still stores its last position blob and, on an adapter that keeps one, its whole input log (ADR-0010) - the host's own event data, at rest, for the life of the store. prune/3 clears both for every execution that ended before a cutoff the host names, and keeps the execution row itself: its status, its failure, its metadata, its answer and its end stamp stay, so the drained query still counts it, a parent can still read a child's answer, and the execution id stays taken.

There is no clock here. The cutoff is a DateTime.t/0 the host computes from its own policy; nothing in this module takes a duration, defaults a window, or runs on a schedule (ADR-0012 decision 7). Which rows a host may delete on its own, and which it must not, is docs/retention.md.

Summary

Types

Options prune/3 accepts.

Functions

Clears the position blob and the input log of every execution that ended before cutoff, in batches, and answers what it cleared.

Types

prune_opt()

@type prune_opt() :: {:batch_size, pos_integer()}

Options prune/3 accepts.

Functions

prune(store, cutoff, opts \\ [])

Clears the position blob and the input log of every execution that ended before cutoff, in batches, and answers what it cleared.

An execution is pruned when its status is :completed, :failed or :cancelled and its ended_at is set and strictly before cutoff. An execution with no end stamp is never touched, and neither is one whose row carries a stamp but was written back to a status that is not terminal. The execution row stays; see the moduledoc for what it keeps.

Answers {:ok, counts} summed over every batch: executions pruned, position_blobs nulled among them, and input log rows deleted. It is idempotent: a second call with the same cutoff answers zeros, because an execution with nothing left to clear is not selected again.

Each batch is one atomic unit in the adapter and commits on its own. So an {:error, reason} from a later batch leaves the earlier batches pruned, and calling again with the same cutoff carries on from where the failed batch stopped.

{:error, :execution_pruning_unsupported} for a store whose adapter does not declare the capability (StatifierPersistence.Storage.execution_pruning_supported?/1), before anything is read.

Raises ArgumentError when cutoff is not a DateTime.t/0 - a duration, a number of days or a Date included - and when :batch_size is not a positive integer.

Options

  • :batch_size - at most how many executions one batch prunes. Defaults to 500. Smaller batches hold shorter transactions; the answer is the same.