Skip to content

Commit

Permalink
Keep existing data if we can't decode source.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Nov 22, 2024
1 parent 6028992 commit a5b34cc
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/screens/last_trip/poller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Screens.LastTrip.Poller do
@moduledoc """
GenServer that polls predictions to calculate the last trip of the day
"""
require Logger
alias Screens.LastTrip.Cache
alias Screens.LastTrip.Parser
alias Screens.LastTrip.TripUpdates
Expand Down Expand Up @@ -32,14 +33,20 @@ defmodule Screens.LastTrip.Poller do
:ok = Cache.reset()
%{state | next_reset: next_reset()}
else
{:ok,
%{
trip_updates: trip_updates,
vehicle_positions: vehicle_positions
}} = fetch_trip_updates_and_vehicle_positions()

update_last_trips(trip_updates)
update_recent_departures(trip_updates, vehicle_positions)
case fetch_trip_updates_and_vehicle_positions() do
{:ok,
%{
trip_updates: trip_updates,
vehicle_positions: vehicle_positions
}} ->
update_last_trips(trip_updates)
update_recent_departures(trip_updates, vehicle_positions)

{:error, error} ->
Logger.warning(
"[last_trip_poller] failed while polling for new data: #{inspect(error)}"
)
end

state
end
Expand All @@ -57,6 +64,8 @@ defmodule Screens.LastTrip.Poller do
trip_updates: trip_updates,
vehicle_positions: vehicle_positions
}}
else
{:error, error} -> {:error, error}
end
end

Expand Down

0 comments on commit a5b34cc

Please sign in to comment.