Skip to content

Commit

Permalink
Better error handling for gtfsrealtime-update
Browse files Browse the repository at this point in the history
  • Loading branch information
brendannee committed Sep 12, 2024
1 parent c57cf98 commit 61a1934
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 36 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- Better error handling for `gtfsrealtime-update`

## [4.14.2] - 2024-09-11

### Fixed
Expand Down
80 changes: 44 additions & 36 deletions src/lib/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,30 +810,30 @@ export async function importGtfs(initialConfig: Config) {
path: any;
prefix: any;
}) => {
const tempPath = temporaryDirectory();

const task = {
exclude: agency.exclude,
url: agency.url,
headers: agency.headers,
realtimeAlerts: agency.realtimeAlerts,
realtimeTripUpdates: agency.realtimeTripUpdates,
realtimeVehiclePositions: agency.realtimeVehiclePositions,
downloadDir: tempPath,
downloadTimeout: config.downloadTimeout,
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
path: agency.path,
csvOptions: config.csvOptions || {},
ignoreDuplicates: config.ignoreDuplicates,
sqlitePath: config.sqlitePath,
prefix: agency.prefix,
currentTimestamp: Math.floor(Date.now() / 1000),
log,
logWarning,
logError,
};

try {
const tempPath = temporaryDirectory();

const task = {
exclude: agency.exclude,
url: agency.url,
headers: agency.headers,
realtimeAlerts: agency.realtimeAlerts,
realtimeTripUpdates: agency.realtimeTripUpdates,
realtimeVehiclePositions: agency.realtimeVehiclePositions,
downloadDir: tempPath,
downloadTimeout: config.downloadTimeout,
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
path: agency.path,
csvOptions: config.csvOptions || {},
ignoreDuplicates: config.ignoreDuplicates,
sqlitePath: config.sqlitePath,
prefix: agency.prefix,
currentTimestamp: Math.floor(Date.now() / 1000),
log,
logWarning,
logError,
};

if (task.url) {
await downloadFiles(task);
}
Expand Down Expand Up @@ -890,20 +890,28 @@ export async function updateGtfsRealtime(initialConfig: Config) {

await Promise.all(
config.agencies.map(async (agency) => {
const task = {
realtimeAlerts: agency.realtimeAlerts,
realtimeTripUpdates: agency.realtimeTripUpdates,
realtimeVehiclePositions: agency.realtimeVehiclePositions,
downloadTimeout: config.downloadTimeout,
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
sqlitePath: config.sqlitePath,
currentTimestamp: Math.floor(Date.now() / 1000),
log,
logWarning,
logError,
};
try {
const task = {
realtimeAlerts: agency.realtimeAlerts,
realtimeTripUpdates: agency.realtimeTripUpdates,
realtimeVehiclePositions: agency.realtimeVehiclePositions,
downloadTimeout: config.downloadTimeout,
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
sqlitePath: config.sqlitePath,
currentTimestamp: Math.floor(Date.now() / 1000),
log,
logWarning,
logError,
};

await updateRealtimeData(task);
await updateRealtimeData(task);
} catch (error: any) {
if (config.ignoreErrors) {
logError(error.message);
} else {
throw error;
}
}
}),
);

Expand Down

0 comments on commit 61a1934

Please sign in to comment.