defmodule OhMyExOhIrcd.Sightings.Pruner do
@moduledoc """
Deletes expired unregistered sightings via `Sightings.prune/0`: once
shortly after boot, then every `:sightings, :prune_interval_ms`
(default 6h). Runs on every node; the sweep is one DELETE … WHERE, so
concurrent runs across the cluster are harmless.
"""
use GenServer
require Logger
alias OhMyExOhIrcd.Sightings
@first_sweep_ms 30_000
def start_link(opts), do: GenServer.start_link(__MODULE__, opts, name: __MODULE__)
@impl true
def init(_opts) do
if Sightings.prune_enabled?(), do: schedule(@first_sweep_ms)
{:ok, %{}}
end
@impl true
def handle_info(:sweep, state) do
sweep()
schedule(Sightings.prune_interval_ms())
{:noreply, state}
end
def handle_info(_, state), do: {:noreply, state}
defp schedule(ms), do: Process.send_after(self(), :sweep, ms)
defp sweep do
n = Sightings.prune()
Logger.info(
"Sightings: removed #{n} unregistered row(s) not seen in " <>
"#{Sightings.unregistered_retention_days()} days"
)
rescue
e -> Logger.warning("Sightings prune failed: #{Exception.message(e)}")
end
end
neiam
/oh-my-ex-oh-ircd
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
1.1 KiB · text
History
4b6fe3b