neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions failure · Badges · Packages
⭐
Log in to mark this repository.
GTFS: an occupancy number the enum does not know reads as none, not a loop
5772d6b · Gabe Morell · 2026-11-04 21:21
Files changed
modified
apps/room_gtfs/lib/room_gtfs/gtfs_worker.ex
+9
−6
@@ -565,15 +565,18 @@ defmodule RoomGtfs.Worker do
| 565 | 565 | defp occupancy_status(status) when is_atom(status), do: status |
| 566 | 566 | |
| 567 | 567 | # A feed may send a number outside the enum the generated module knows; that |
| 568 | − # is not an occupancy anyone can draw, so it reads as no answer. | |
| 569 | − defp occupancy_status(status) when is_integer(status) do | |
| 570 | − try do | |
| 571 | − TransitRealtime.VehiclePosition.OccupancyStatus.key(status) |> occupancy_status() | |
| 572 | − rescue | |
| 573 | − _ -> nil | |
| 568 | + # is not an occupancy anyone can draw, so it reads as no answer. key/1 hands | |
| 569 | + # an unknown non-negative number back unchanged, so only an atom goes round | |
| 570 | + # again; it raises on a negative one, which never reaches it. | |
| 571 | + defp occupancy_status(status) when is_integer(status) and status >= 0 do | |
| 572 | + case TransitRealtime.VehiclePosition.OccupancyStatus.key(status) do | |
| 573 | + key when is_atom(key) -> occupancy_status(key) | |
| 574 | + _unknown -> nil | |
| 574 | 575 | end |
| 575 | 576 | end |
| 576 | 577 | |
| 578 | + defp occupancy_status(status) when is_integer(status), do: nil | |
| 579 | + | |
| 577 | 580 | # etc |
| 578 | 581 | def init(opts) do |
| 579 | 582 | Configuration.subscribe(:source, opts[:name]) |
Parents: b722703