defmodule GitGud.Audit.Workers.Prune do
@moduledoc """
Deletes audit entries older than the configured window — and nothing,
by default:
# nil keeps every entry; N prunes entries older than N days.
config :git_gud, GitGud.Audit, retention_days: nil
Deliberately config, not an admin setting: shortening the audit trail
takes a deploy, not a session. A prune that removed anything leaves
its own `audit.pruned` entry.
"""
use Oban.Worker, queue: :default, max_attempts: 3
alias GitGud.Audit
alias GitGud.Audit.Actor
@impl Oban.Worker
def perform(_job) do
case Audit.retention_days!() do
nil ->
:ok
days ->
cutoff = DateTime.add(DateTime.utc_now(), -days * 86_400, :second)
case Audit.prune(cutoff) do
0 ->
:ok
count ->
Audit.record(Actor.system(:cron), "audit.pruned", %{
metadata: %{count: count, cutoff: cutoff}
})
:ok
end
end
end
end
neiam
/gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
1
Log in to mark this repository.
1019 B · text
History
8ccf537