Prevent shuttle arriving at same stop from firing the SHUTTLE_WILL_ARRIVE_AT_STOP event

This commit is contained in:
2025-11-11 21:22:39 -08:00
parent 4096c0ce44
commit 1866224b5b
3 changed files with 11 additions and 1 deletions

View File

@@ -395,7 +395,11 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
) {
const arrivedStop = await this.getArrivedStopIfExists(shuttle);
if (arrivedStop != undefined) {
if (arrivedStop) {
// stop if same stop
const lastStop = await this.getShuttleLastStopArrival(shuttle.id);
if (lastStop?.stopId === arrivedStop.id) return;
const shuttleArrival = {
stopId: arrivedStop.id,
timestamp: new Date(travelTimeTimestamp),

View File

@@ -93,6 +93,9 @@ export class InMemorySelfUpdatingETARepository extends BaseInMemoryETARepository
private async handleShuttleWillArriveAtStop(shuttleArrival: ShuttleStopArrival): Promise<void> {
const lastStopTimestamp = await this.shuttleRepository.getShuttleLastStopArrival(shuttleArrival.shuttleId);
if (lastStopTimestamp) {
// disallow cases where this gets triggered multiple times
if (lastStopTimestamp.stopId === shuttleArrival.stopId) return;
const shuttle = await this.shuttleRepository.getShuttleById(lastStopTimestamp.shuttleId);
if (!shuttle) return;

View File

@@ -119,6 +119,9 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
) {
const lastStopTimestamp = await this.shuttleRepository.getShuttleLastStopArrival(shuttleArrival.shuttleId);
if (lastStopTimestamp) {
// disallow cases where this gets triggered multiple times
if (lastStopTimestamp.stopId === shuttleArrival.stopId) return;
const shuttle = await this.shuttleRepository.getShuttleById(lastStopTimestamp.shuttleId);
if (!shuttle) return;