prop/lib/microwaveprop/workers/grid_cache_prune_worker.ex
Graham McIntire 8e73583926
feat(workers): add GridCachePruneWorker
The Microwaveprop.Weather.GridCache ETS table grew unbounded — each
hourly PropagationGridWorker run plus peer broadcast_put added ~92k
points per forecast hour, so long-lived pods were strong OOM
candidates. GridCache already exposed prune_older_than/1 but nothing
called it.

Adds an Oban worker on the :propagation queue (lower priority than
the grid chain) that prunes entries older than 3 hours. Scheduled
hourly at :15 in dev, prod, and the base crontab.
2026-04-21 13:19:52 -05:00

28 lines
940 B
Elixir

defmodule Microwaveprop.Workers.GridCachePruneWorker do
@moduledoc """
Prunes stale rows from the node-local `Microwaveprop.Weather.GridCache` ETS
table. Without this cron the cache grew unbounded: every hourly
`PropagationGridWorker` run plus peer `broadcast_put` added an entry per
forecast hour (~92k points * 19 hours), so long-lived pods eventually OOM'd.
Runs on the shared `:propagation` queue alongside `PropagationPruneWorker`
at a lower priority so the hourly grid chain never waits behind it.
"""
use Oban.Worker,
queue: :propagation,
priority: 5,
max_attempts: 3,
unique: [period: 300, states: [:available, :scheduled, :executing, :retryable]]
alias Microwaveprop.Weather.GridCache
@cutoff_hours 3
@impl Oban.Worker
def perform(%Oban.Job{}) do
cutoff = DateTime.add(DateTime.utc_now(), -@cutoff_hours, :hour)
_removed = GridCache.prune_older_than(cutoff)
:ok
end
end