defmodule GitGud.Packages.Workers.Prune do
@moduledoc """
The nightly retention pass.
Does nothing at all until an admin turns `packages.retention_enforced`
on — it still runs, and still logs what it *would* free, which is the
number the admin view shows and the reason the job exists before
anyone has decided to enable it.
Scheduled from `config/config.exs`. Daily rather than hourly: a
registry's disk problem develops over weeks, and a nightly job is
easier to reason about after the fact than one that fires while
someone is publishing.
"""
use Oban.Worker, queue: :default, max_attempts: 3
require Logger
alias GitGud.Packages.DiskUsage
alias GitGud.Packages.Pruner
@impl Oban.Worker
def perform(%Oban.Job{args: args}) do
opts = if args["force"], do: [force: true], else: []
{:ok, result} = Pruner.prune_all(opts)
case result do
%{status: :pruned, pruned: n, bytes: bytes} ->
Logger.info(
"retention: pruned #{n} version(s), freed #{DiskUsage.humanize(bytes)}" <>
failures(result)
)
%{pruned: n, bytes: bytes} ->
Logger.info(
"retention: reporting only — would prune #{n} version(s), " <>
"freeing #{DiskUsage.humanize(bytes)} " <>
"(enable packages.retention_enforced to act on it)"
)
end
:ok
end
defp failures(%{failed: []}), do: ""
defp failures(%{failed: failed}),
do: "; #{length(failed)} kept after errors: #{inspect(Enum.take(failed, 3))}"
end
neiam
/gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
1
Log in to mark this repository.
1.5 KiB · text
History
aa9e861