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

43 lines
1.2 KiB
Elixir

defmodule Microwaveprop.Workers.StationElevationWorker do
@moduledoc """
Oban worker that enriches a `FixedStation` row with its SRTM
elevation. Enqueued from `Microwaveprop.Rover.create_station/2`
whenever the user-supplied attrs leave `elevation_m` nil.
A missing tile or a void value is non-fatal — the row simply stays
with `elevation_m = nil`. The worker also no-ops if the station has
been deleted between enqueue and execution.
"""
use Oban.Pro.Worker, queue: :terrain, max_attempts: 3
alias Microwaveprop.Repo
alias Microwaveprop.Rover.FixedStation
alias Microwaveprop.Terrain.Srtm
@impl Oban.Worker
def perform(%Oban.Job{args: %{"id" => id}}) do
case Repo.get(FixedStation, id) do
nil ->
:ok
station ->
update_elevation(station)
end
end
defp update_elevation(station) do
tiles_dir = Application.get_env(:microwaveprop, :srtm_tiles_dir, "/data/srtm")
case Srtm.lookup(station.lat, station.lon, tiles_dir) do
{:ok, elev} ->
station
|> Ecto.Changeset.change(elevation_m: elev)
|> Repo.update()
:ok
{:error, _} ->
:ok
end
end
end