diff --git a/internal/gtfs/gtfs_manager.go b/internal/gtfs/gtfs_manager.go index 3703f39d..73f31f2f 100644 --- a/internal/gtfs/gtfs_manager.go +++ b/internal/gtfs/gtfs_manager.go @@ -413,8 +413,9 @@ func (manager *Manager) VehiclesForAgencyID(agencyID string) []gtfs.Vehicle { // for that trip. Note we depend on getting the vehicle that may not match the trip ID exactly, // but is part of the same block. // IMPORTANT: Caller must hold manager.RLock() before calling this method. -func (manager *Manager) GetVehicleForTrip(tripID string) *gtfs.Vehicle { - ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) +func (manager *Manager) GetVehicleForTrip(ctx context.Context, tripID string) *gtfs.Vehicle { + + ctx, cancel := context.WithTimeout(ctx, 2*time.Second) defer cancel() logger := slog.Default().With(slog.String("component", "gtfs_manager")) diff --git a/internal/gtfs/gtfs_manager_test.go b/internal/gtfs/gtfs_manager_test.go index 1f321972..812e25aa 100644 --- a/internal/gtfs/gtfs_manager_test.go +++ b/internal/gtfs/gtfs_manager_test.go @@ -353,7 +353,7 @@ func TestManager_GetVehicleForTrip(t *testing.T) { manager.rebuildMergedRealtimeLocked() - vehicle := manager.GetVehicleForTrip("5735633") + vehicle := manager.GetVehicleForTrip(context.Background(), "5735633") if vehicle != nil { assert.NotNil(t, vehicle) assert.Equal(t, "vehicle1", vehicle.ID.ID) diff --git a/internal/restapi/arrival_and_departure_for_stop_handler.go b/internal/restapi/arrival_and_departure_for_stop_handler.go index 57a6179d..894418ed 100644 --- a/internal/restapi/arrival_and_departure_for_stop_handler.go +++ b/internal/restapi/arrival_and_departure_for_stop_handler.go @@ -266,7 +266,7 @@ func (api *RestAPI) arrivalAndDepartureForStopHandler(w http.ResponseWriter, r * } } else { // If vehicleId is not provided, get the vehicle for the trip - vehicle = api.GtfsManager.GetVehicleForTrip(tripID) + vehicle = api.GtfsManager.GetVehicleForTrip(ctx, tripID) } if vehicle != nil && vehicle.Trip != nil { diff --git a/internal/restapi/arrivals_and_departure_for_stop.go b/internal/restapi/arrivals_and_departure_for_stop.go index eb59226d..bb96bed8 100644 --- a/internal/restapi/arrivals_and_departure_for_stop.go +++ b/internal/restapi/arrivals_and_departure_for_stop.go @@ -292,7 +292,7 @@ func (api *RestAPI) arrivalsAndDeparturesForStopHandler(w http.ResponseWriter, r ) // Get real-time updates from GTFS-RT - vehicle := api.GtfsManager.GetVehicleForTrip(st.TripID) + vehicle := api.GtfsManager.GetVehicleForTrip(ctx, st.TripID) if vehicle != nil && vehicle.Trip != nil { vehicleID = vehicle.ID.ID diff --git a/internal/restapi/trips_helper.go b/internal/restapi/trips_helper.go index 090a9d69..3851da77 100644 --- a/internal/restapi/trips_helper.go +++ b/internal/restapi/trips_helper.go @@ -24,7 +24,7 @@ func (api *RestAPI) BuildTripStatus( currentTime time.Time, ) (*models.TripStatusForTripDetails, error) { - vehicle := api.GtfsManager.GetVehicleForTrip(tripID) + vehicle := api.GtfsManager.GetVehicleForTrip(ctx, tripID) var occupancyStatus string var vehicleID string