mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Add logic to clear out previous ETAs
This commit is contained in:
@@ -3,7 +3,8 @@ import { BaseRedisETARepository } from "./BaseRedisETARepository";
|
||||
import { createClient, RedisClientType } from "redis";
|
||||
import { ShuttleGetterRepository, ShuttleRepositoryEvent, ShuttleStopArrival, ShuttleTravelTimeDataIdentifier, ShuttleTravelTimeDateFilterArguments } from "../ShuttleGetterRepository";
|
||||
import { REDIS_RECONNECT_INTERVAL } from "../../../environment";
|
||||
import { IOrderedStop, IShuttle } from "../../../entities/ShuttleRepositoryEntities";
|
||||
import { IEta, IOrderedStop, IShuttle } from "../../../entities/ShuttleRepositoryEntities";
|
||||
import { ETARepositoryEvent } from "./ETAGetterRepository";
|
||||
|
||||
export class RedisSelfUpdatingETARepository extends BaseRedisETARepository implements SelfUpdatingETARepository {
|
||||
constructor(
|
||||
@@ -176,6 +177,11 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
|
||||
private async handleShuttleWillArriveAtStop(
|
||||
shuttleArrival: ShuttleStopArrival,
|
||||
) {
|
||||
const etas = await this.getEtasForShuttleId(shuttleArrival.shuttleId);
|
||||
for (const eta of etas) {
|
||||
await this.removeEtaIfExists(eta.shuttleId, eta.stopId);
|
||||
}
|
||||
|
||||
const lastStopTimestamp = await this.shuttleRepository.getShuttleLastStopArrival(shuttleArrival.shuttleId);
|
||||
if (lastStopTimestamp) {
|
||||
// disallow cases where this gets triggered multiple times
|
||||
@@ -265,4 +271,15 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
|
||||
}
|
||||
}
|
||||
|
||||
private async removeEtaIfExists(shuttleId: string, stopId: string): Promise<IEta | null> {
|
||||
const existingEta = await this.getEtaForShuttleAndStopId(shuttleId, stopId);
|
||||
if (existingEta === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const key = this.createEtaKey(shuttleId, stopId);
|
||||
await this.redisClient.del(key);
|
||||
this.emit(ETARepositoryEvent.ETA_REMOVED, existingEta);
|
||||
return existingEta;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user