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
8 changes: 4 additions & 4 deletions internal/gtfs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/gtfs/gtfs_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions internal/gtfs/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
Expand Down
Loading