Deletes old finished runs of DAGs that set a run retention.
A DAG opts in with runs: [retention: [max_count: n]]: its n most recent
finished (:succeeded or :failed) runs are kept and older ones are
deleted, together with their tasks and logs. Unfinished runs are never
deleted and don't count toward n. DAGs without a retention keep all runs.
Pruning runs on a schedule only when the app configures one:
config :gust, :run_pruner, schedule: "@daily", deletion_batch_size: 200schedule- a crontab expression, including shortcuts such as@hourlyor@daily.Gust.DAG.Run.Cron.Schedulerregisters the job, so it runs on the leader only and never overlaps itself. Without it nothing is deleted, unlessprune/3is called directly (e.g. by the CLI).deletion_batch_size- runs deleted per statement. Defaults to 200; anything but a positive integer uses the default.
Runs are deleted in batches, each one a single short statement, and every
batch broadcasts Gust.PubSub.broadcast_runs_pruned/2 so open dashboards
drop the deleted runs. The number of runs deleted per DAG is logged.
Deleting rows doesn't shrink tables on disk: autovacuum makes the space
reusable, so tables stop growing. Use VACUUM FULL or pg_repack once to
reclaim space on instances that are already large.
Summary
Functions
Returns the schedule as configured, or nil when it isn't set.
Returns the configured deletion_batch_size, or the default of
200 when it's unset or not a positive integer.
Deletes the finished runs of a DAG beyond the max_count most recent ones
and returns how many were deleted.
Prunes every loaded DAG that sets a retention.
Lists the loaded DAGs that set a retention, sorted by name.
Returns the configured schedule, parsed.
Functions
@spec configured_schedule() :: term()
Returns the schedule as configured, or nil when it isn't set.
@spec deletion_batch_size() :: pos_integer()
Returns the configured deletion_batch_size, or the default of
200 when it's unset or not a positive integer.
@spec prune(integer(), pos_integer(), keyword()) :: non_neg_integer()
Deletes the finished runs of a DAG beyond the max_count most recent ones
and returns how many were deleted.
Options
:dry_run- whentrue, deletes nothing and returns how many runs would be deleted. Defaults tofalse.
@spec prune_all() :: %{required(String.t()) => non_neg_integer()}
Prunes every loaded DAG that sets a retention.
Returns a map of DAG name to the number of runs deleted.
@spec retained_dags() :: [ %{dag_id: integer(), name: String.t(), max_count: pos_integer()} ]
Lists the loaded DAGs that set a retention, sorted by name.
@spec schedule() :: {:ok, Crontab.CronExpression.t()} | :disabled | {:error, String.t()}
Returns the configured schedule, parsed.
Returns :disabled when it isn't configured, and an error for an invalid
expression or @reboot, which would only prune when the Scheduler starts.