prop/lib/microwaveprop/workers/propagation_prune_worker.ex
Graham McIntire 581955bd69
Some checks failed
Build and Push / Build and Push Docker Image (push) Has been cancelled
fix: prevent contacts_dedup_idx collisions in parallel async tests
Create shared ContactsFixtures module with globally-unique qso_timestamp
seconds to prevent unique-constraint violations when async test modules
run in parallel and insert contacts with identical dedup-key columns.
The qso_timestamp column is timestamp(0), so microsecond offsets were
truncated — use System.unique_integer monotonic seconds instead.

Also make count-asserting tests resilient to sandbox-leaked contacts
from prior tests by using >= assertions or status-based checks rather
than exact counts.

Includes automated DateTime.add → DateTime.shift migration from
mix format.
2026-08-04 17:05:16 -05:00

45 lines
1.5 KiB
Elixir

defmodule Microwaveprop.Workers.PropagationPruneWorker do
@moduledoc """
Standalone worker that prunes stale rows from `propagation_scores`.
Pruning used to be tacked on to the end of `PropagationGridWorker.perform/1`,
which meant it only ran after a successful grid compute. When the compute
worker was being killed mid-run (OOM / SIGTERM), prune never ran and the
table grew unbounded. Running prune on its own cron keeps the table healthy
regardless of the compute worker's state.
"""
use Oban.Pro.Worker,
queue: :propagation,
# Lower priority than PropagationGridWorker so the hourly chain
# never waits behind a pending prune on the shared :propagation
# queue (2 slots).
priority: 5,
max_attempts: 3,
unique: [period: 300, states: :incomplete]
alias Microwaveprop.Buildings.MsFootprints
alias Microwaveprop.Canopy
alias Microwaveprop.Propagation
require Logger
@impl Oban.Pro.Worker
def process(%Oban.Job{}) do
Propagation.prune_old_scores()
cutoff_30d = DateTime.shift(DateTime.utc_now(), day: -30)
buildings_deleted = MsFootprints.prune_older_than(cutoff_30d)
canopy_deleted = Canopy.prune_older_than(cutoff_30d)
if buildings_deleted > 0 do
Logger.info("MsFootprints: pruned #{buildings_deleted} cached tile files older than #{cutoff_30d}")
end
if canopy_deleted > 0 do
Logger.info("Canopy: pruned #{canopy_deleted} cached tile/staging files older than #{cutoff_30d}")
end
:ok
end
end