Add code to mark shuttle at a stop (Redis set)

This commit is contained in:
2025-11-18 20:27:00 -08:00
parent 4ffdd35b21
commit 78cf60af4a

View File

@@ -84,6 +84,11 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
return `shuttle:eta:historical:${routeId}:${fromStopId}:${toStopId}`;
}
/**
* Represents a set storing the shuttles that are currently at a stop.
*/
private readonly shuttleIsAtStopKey = "shuttle:atstop";
// Helper methods for converting entities to Redis hashes
private createRedisHashFromStop = (stop: IStop): Record<string, string> => ({
id: stop.id,
@@ -409,10 +414,19 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
lastStopArrival: lastStop,
willArriveAt: shuttleArrival,
});
await this.markShuttleAsAtStop(shuttleArrival.shuttleId);
await this.updateShuttleLastStopArrival(shuttleArrival);
}
}
private async markShuttleAsAtStop(shuttleId: string) {
await this.redisClient.sAdd(this.shuttleIsAtStopKey, shuttleId);
}
private async checkIfShuttleIsAtStop(shuttleId: string) {
return await this.redisClient.sIsMember(this.shuttleIsAtStopKey, shuttleId);
}
public async getAverageTravelTimeSeconds(
{ routeId, fromStopId, toStopId }: ShuttleTravelTimeDataIdentifier,
{ from, to }: ShuttleTravelTimeDateFilterArguments,