Gust.Run.Pruner (gust v0.1.43)

Copy Markdown View Source

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: 200
  • schedule - a crontab expression, including shortcuts such as @hourly or @daily. Gust.DAG.Run.Cron.Scheduler registers the job, so it runs on the leader only and never overlaps itself. Without it nothing is deleted, unless prune/3 is 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

configured_schedule()

@spec configured_schedule() :: term()

Returns the schedule as configured, or nil when it isn't set.

deletion_batch_size()

@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.

prune(dag_id, max_count, opts \\ [])

@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 - when true, deletes nothing and returns how many runs would be deleted. Defaults to false.

prune_all()

@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.

retained_dags()

@spec retained_dags() :: [
  %{dag_id: integer(), name: String.t(), max_count: pos_integer()}
]

Lists the loaded DAGs that set a retention, sorted by name.

schedule()

@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.