Skip to content
Merged
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,15 @@ await gtfs.fetchRealtimeData(['./path/to/feed.pb']);
// Update configuration
gtfs.setRealtimeFeedUrls(['https://example.com/new-feed']);
gtfs.setStalenessThreshold(60); // 60 seconds

// Check when realtime data was last fetched
const lastFetch = gtfs.getLastRealtimeFetchTimestamp();
if (lastFetch) {
const ageSeconds = Math.floor(Date.now() / 1000) - lastFetch;
console.log(`RT data is ${ageSeconds} seconds old`);
} else {
console.log('No RT data has been fetched yet');
}
```

#### Querying Alerts
Expand Down Expand Up @@ -1164,6 +1173,7 @@ All methods support flexible filtering with both single values and arrays:
- `getRealtimeFeedUrls()` - Get configured RT feed URLs
- `setStalenessThreshold(seconds)` - Set staleness threshold (default: 120 seconds)
- `getStalenessThreshold()` - Get current staleness threshold
- `getLastRealtimeFetchTimestamp()` - Get Unix timestamp (seconds) of last successful RT fetch, or null if never fetched
- `getAlerts(filters?)` - Get alerts (filters: alertId, routeId, stopId, tripId, activeOnly, cause, effect, limit)
- `getVehiclePositions(filters?)` - Get vehicle positions (filters: tripId, routeId, vehicleId, limit)
- `getTripUpdates(filters?)` - Get trip updates (filters: tripId, routeId, limit)
Expand Down
10 changes: 10 additions & 0 deletions src/gtfs-sqljs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class GtfsSqlJs {
private SQL: SqlJsStatic | null = null;
private realtimeFeedUrls: string[] = [];
private stalenessThreshold: number = 120;
private lastRealtimeFetchTimestamp: number | null = null;

/**
* Private constructor - use static factory methods instead
Expand Down Expand Up @@ -875,6 +876,14 @@ export class GtfsSqlJs {
return this.stalenessThreshold;
}

/**
* Get timestamp of the last successful realtime data fetch and insertion
* @returns Unix timestamp in seconds, or null if no realtime data has been fetched
*/
getLastRealtimeFetchTimestamp(): number | null {
return this.lastRealtimeFetchTimestamp;
}

/**
* Fetch and load GTFS Realtime data from configured feed URLs or provided URLs
* @param urls - Optional array of feed URLs. If not provided, uses configured feed URLs
Expand All @@ -888,6 +897,7 @@ export class GtfsSqlJs {
}

await loadRealtimeData(this.db, feedUrls);
this.lastRealtimeFetchTimestamp = Math.floor(Date.now() / 1000);
}

/**
Expand Down