prop/lib/microwaveprop/workers/rover_mission_reconcile_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

45 lines
1.4 KiB
Elixir
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

defmodule Microwaveprop.Workers.RoverMissionReconcileWorker do
@moduledoc """
Async reconciler for one rover-planning mission's path matrix.
Form saves (mission edits, add/remove rover site) enqueue this job
instead of running the reconcile inline — for a mission with many
rover sites × stations × bands the inline path produced a multi-
hundred-row Multi transaction + as many `Oban.insert/1` calls,
which made the form submit feel sluggish.
The reconcile itself is idempotent: deleting stale (mission_id,
rover_location_id, station_id, band_mhz) rows, leaving :complete
rows in place, and enqueueing per-pair compute jobs only for the
tuples that aren't already represented.
"""
use Oban.Pro.Worker,
queue: :terrain,
priority: 3,
max_attempts: 3,
unique: [
period: 60,
keys: [:mission_id],
states: :incomplete
]
import Ecto.Query
alias Microwaveprop.Repo
alias Microwaveprop.RoverPlanning
alias Microwaveprop.RoverPlanning.Mission
alias Microwaveprop.RoverPlanning.Station
@impl Oban.Worker
def perform(%Oban.Job{args: %{"mission_id" => mission_id}}) do
case Repo.get(Mission, mission_id) do
nil ->
:ok
mission ->
mission
|> Repo.preload([:user, stations: from(s in Station, order_by: s.position)])
|> RoverPlanning.reconcile_mission_paths()
end
end
end