Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions internal/gtfs/gtfs_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion internal/gtfs/gtfs_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/restapi/arrival_and_departure_for_stop_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/restapi/arrivals_and_departure_for_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/restapi/trips_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading