Stop the RT workers crashing on their first poll

bf3e0f1 · Gabriel Morell · 2026-08-24 13:21

5 files +10 -2
Message
{commit_body(@commit)}

Files changed

modified apps/room_gtfs/lib/room_gtfs/gtfs_worker.ex
+10 −2
@@ -524,9 +524,17 @@ defmodule RoomGtfs.Worker.RT do
524 524 # subway feed is 1,488 rows that would otherwise be read on every poll.
525 525 defp ensure_stops(state) do
526 526 now = System.monotonic_time(:millisecond)
527 − age = now - Map.get(state, :stops_at, -@stops_ttl)
528 527
529 − if age >= @stops_ttl do
528 + # Matched rather than defaulted: the key is present from init with a value of
529 + # nil, so Map.get/3's default never fired and the first poll of every worker
530 + # arithmetic'd against nil.
531 + stale? =
532 + case state.stops_at do
533 + nil -> true
534 + at -> now - at >= @stops_ttl
535 + end
536 +
537 + if stale? do
530 538 stops =
531 539 state.id
532 540 |> Storage.list_stops()

Parents: 819e9cd