diff --git a/internal/gtfs/config.go b/internal/gtfs/config.go index 2b189e62..4edd8e98 100644 --- a/internal/gtfs/config.go +++ b/internal/gtfs/config.go @@ -25,10 +25,10 @@ type Config struct { StaticAuthHeaderValue string RTFeeds []RTFeedConfig GTFSDataPath string - Env appconf.Environment - Verbose bool - EnableGTFSTidy bool - StartupRetries []time.Duration + Env appconf.Environment + Verbose bool + EnableGTFSTidy bool + StartupRetries []time.Duration // Backoff durations between startup load attempts; defaults to [5s,15s,30s,60s] } // enabledFeeds returns only the enabled feeds that have at least one URL configured. diff --git a/internal/gtfs/gtfs_manager.go b/internal/gtfs/gtfs_manager.go index 1f5a8edd..52d6fcf7 100644 --- a/internal/gtfs/gtfs_manager.go +++ b/internal/gtfs/gtfs_manager.go @@ -113,7 +113,7 @@ func InitGTFSManager(ctx context.Context, config Config) (*Manager, error) { attemptsMade = attempt // Attempt to load in-memory static data if we haven't already succeeded if staticData == nil { - staticData, err = loadGTFSData(config.GtfsURL, isLocalFile, config) + staticData, err = loadGTFSData(ctx, config.GtfsURL, isLocalFile, config) if err != nil { if attempt < maxAttempts { delay := backoffs[attempt-1] diff --git a/internal/gtfs/static.go b/internal/gtfs/static.go index b2c1d5e0..3e2f6593 100644 --- a/internal/gtfs/static.go +++ b/internal/gtfs/static.go @@ -15,7 +15,7 @@ import ( "maglev.onebusaway.org/internal/logging" ) -func rawGtfsData(source string, isLocalFile bool, config Config) ([]byte, error) { +func rawGtfsData(ctx context.Context, source string, isLocalFile bool, config Config) ([]byte, error) { var b []byte var err error @@ -27,7 +27,7 @@ func rawGtfsData(source string, isLocalFile bool, config Config) ([]byte, error) return nil, fmt.Errorf("error reading local GTFS file: %w", err) } } else { - req, err := http.NewRequest("GET", source, nil) + req, err := http.NewRequestWithContext(ctx, "GET", source, nil) if err != nil { return nil, fmt.Errorf("error creating GTFS request: %w", err) } @@ -121,8 +121,8 @@ func buildGtfsDB(ctx context.Context, config Config, isLocalFile bool, dbPath st } // loadGTFSData loads and parses GTFS data from either a URL or a local file -func loadGTFSData(source string, isLocalFile bool, config Config) (*gtfs.Static, error) { - b, err := rawGtfsData(source, isLocalFile, config) +func loadGTFSData(ctx context.Context, source string, isLocalFile bool, config Config) (*gtfs.Static, error) { + b, err := rawGtfsData(ctx, source, isLocalFile, config) if err != nil { return nil, fmt.Errorf("error reading GTFS data: %w", err) } @@ -196,7 +196,7 @@ func (manager *Manager) ForceUpdate(ctx context.Context) error { logger := slog.Default().With(slog.String("component", "gtfs_updater")) - newStaticData, err := loadGTFSData(manager.config.GtfsURL, manager.isLocalFile, manager.config) + newStaticData, err := loadGTFSData(ctx, manager.config.GtfsURL, manager.isLocalFile, manager.config) if err != nil { logging.LogError(logger, "Error updating GTFS data", err, slog.String("source", manager.config.GtfsURL))