Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle LastTrip polling errors #2310

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 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)}"
digitalcora marked this conversation as resolved.
Show resolved Hide resolved
)
end

state
end
Expand Down
5 changes: 4 additions & 1 deletion lib/screens/last_trip/trip_updates/noop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ defmodule Screens.LastTrip.TripUpdates.Noop do

@impl true
def get do
{:ok, %{status_code: 200, body: %{"entity" => []}}}
case Jason.decode("{\"entity\":[]}") do
digitalcora marked this conversation as resolved.
Show resolved Hide resolved
{:ok, decoded} -> {:ok, %{status_code: 200, body: decoded}}
error -> error
end
end
end
5 changes: 4 additions & 1 deletion lib/screens/last_trip/vehicle_positions/noop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ defmodule Screens.LastTrip.VehiclePositions.Noop do

@impl true
def get do
{:ok, %HTTPoison.Response{status_code: 200, body: %{"entity" => []}}}
case Jason.decode("{\"entity\":[]}") do
{:ok, decoded} -> {:ok, %HTTPoison.Response{status_code: 200, body: decoded}}
error -> error
end
end
end
Loading