prop/lib/microwaveprop/workers/grid_cache_prune_worker.ex
Graham McIntire fd976b0cd5
fix: resolve 391 Credo issues across codebase
- Add jump_credo_checks ~> 0.4 with all 20 checks enabled
- Fix all standard Credo issues: 139 @spec (113 done, 26 remain),
  4 refactoring, 3 alias usage, 9 System.cmd env, 5 unsafe_to_atom,
  2 max line length, 9 assert_receive timeout
- Fix 170+ jump_credo_checks warnings:
  - 117 TopLevelAliasImportRequire: move nested alias/import to module top
  - 32 UseObanProWorker: switch to Oban.Pro.Worker
  - 4 DoctestIExExamples: add doctests / create test file
  - ~20 WeakAssertion: strengthen type-check assertions
  - Various ConditionalAssertion, AssertReceiveTimeout fixes
- Exclude vendor/ from Credo analysis
- Remaining: 175 warnings (mostly opinionated WeakAssertion,
  AvoidSocketAssignsInTest), 26 @spec annotations
2026-06-12 13:51:32 -05:00

28 lines
907 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.Pro.Worker,
queue: :propagation,
priority: 5,
max_attempts: 3,
unique: [period: 300, states: :incomplete]
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