finish the rename for the data loaders

This commit is contained in:
2025-03-27 09:33:37 -07:00
parent fab99db755
commit 687fe0d826
7 changed files with 16 additions and 16 deletions

View File

@@ -1,64 +0,0 @@
import { ShuttleGetterSetterRepository } from "../repositories/ShuttleGetterSetterRepository";
import { ApiBasedRepositoryLoader } from "./ApiBasedRepositoryLoader";
// Ideas to break this into smaller pieces in the future:
// Have one repository data loader running for each supported system
// Each data loader independently updates data based on frequency of usage
// Notes on this: we only need to reload ETA data frequently
// Other data can be reloaded periodically
// Detailed list:
// - ETA: reload frequently or switch to write-through approach
// - Shuttles: reload every minute
// - Routes: reload every few minutes
// - Stops: reload every few minutes
// - OrderedStops: reload every few minutes
// - Systems: reload once a day
export class TimedApiBasedRepositoryLoader extends ApiBasedRepositoryLoader {
private shouldBeRunning: boolean = false;
private timer: any;
readonly timeout = 10000;
constructor(
repository: ShuttleGetterSetterRepository,
) {
super(repository);
this.startFetchDataAndUpdate = this.startFetchDataAndUpdate.bind(this);
}
public async start() {
if (this.shouldBeRunning) {
console.warn("DataLoader timer is already running");
return;
}
this.shouldBeRunning = true;
await this.startFetchDataAndUpdate();
}
public stop() {
this.shouldBeRunning = false;
}
private async startFetchDataAndUpdate() {
if (!this.shouldBeRunning) return;
try {
await this.fetchAndUpdateSystemData();
await this.fetchAndUpdateRouteDataForExistingSystemsInRepository();
await this.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository();
await this.fetchAndUpdateShuttleDataForExistingSystemsInRepository();
// Because ETA method doesn't support pruning yet,
// add a call to the clear method here
await this.repository.clearEtaData();
await this.fetchAndUpdateEtaDataForExistingStopsForSystemsInRepository();
} catch (e) {
console.error(e);
}
this.timer = setTimeout(this.startFetchDataAndUpdate, this.timeout);
}
}