From 4b4aabf59fbcab8e1e2b0512e5f708f07137f486 Mon Sep 17 00:00:00 2001 From: Jono Cooper Date: Mon, 8 Jul 2019 21:30:55 +1200 Subject: [PATCH] Fix Auckland Realtime Regression --- src/waka-orchestrator/index.ts | 1 + src/waka-worker/realtime/index.ts | 2 +- src/waka-worker/realtime/regions/nz-akl.ts | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/waka-orchestrator/index.ts b/src/waka-orchestrator/index.ts index 4bba555..e919778 100644 --- a/src/waka-orchestrator/index.ts +++ b/src/waka-orchestrator/index.ts @@ -97,6 +97,7 @@ class WakaOrchestrator { bindRoutes() { const { gateway, router, privateApi, config } = this + router.get('/', (req: Request, res: Response) => res.redirect('/private')) router.get('/ping', (req: Request, res: Response) => res.send('pong')) router.use('/private', privateApi.router) diff --git a/src/waka-worker/realtime/index.ts b/src/waka-worker/realtime/index.ts index 9fded9e..69b4430 100644 --- a/src/waka-worker/realtime/index.ts +++ b/src/waka-worker/realtime/index.ts @@ -8,7 +8,7 @@ import { BaseRealtime, WakaRequest } from '../../typings' const regions = { 'au-syd': RealtimeAUSYD, - // 'nz-akl': RealtimeNZAKL, + 'nz-akl': RealtimeNZAKL, 'nz-wlg': RealtimeNZWLG, } diff --git a/src/waka-worker/realtime/regions/nz-akl.ts b/src/waka-worker/realtime/regions/nz-akl.ts index 8f09395..b904a16 100644 --- a/src/waka-worker/realtime/regions/nz-akl.ts +++ b/src/waka-worker/realtime/regions/nz-akl.ts @@ -20,6 +20,9 @@ class RealtimeNZAKL extends BaseRealtime { currentDataFails: number currentVehicleDataFails: number + tripUpdateTimeout: NodeJS.Timer + locationTimeout: NodeJS.Timer + tripUpdatesOptions: { url: string; headers: { [header: string]: string } } vehicleLocationsOptions: { url: string @@ -40,6 +43,8 @@ class RealtimeNZAKL extends BaseRealtime { this.currentDataFails = 0 this.currentVehicleData = {} this.currentVehicleDataFails = null + this.tripUpdateTimeout = 0 + this.locationTimeout = 0 this.tripUpdatesOptions = { url: 'https://api.at.govt.nz/v2/public/realtime/tripupdates', @@ -78,8 +83,9 @@ class RealtimeNZAKL extends BaseRealtime { } stop() { - // TODO! - this.logger.warn('Auckland Realtime Not Stopped! Not Implemented.') + clearTimeout(this.tripUpdateTimeout) + clearTimeout(this.locationTimeout) + this.logger.info('Auckland Realtime stopped.') } async schedulePull() { @@ -104,7 +110,7 @@ class RealtimeNZAKL extends BaseRealtime { this.currentDataFails += 1 logger.warn({ err }, 'Could not get AT Data') } - setTimeout(this.schedulePull, schedulePullTimeout) + this.tripUpdateTimeout = setTimeout(this.schedulePull, schedulePullTimeout) } async scheduleLocationPull() { @@ -121,7 +127,10 @@ class RealtimeNZAKL extends BaseRealtime { this.currentVehicleDataFails += 1 logger.error({ err }, 'Could not get AT Data') } - setTimeout(this.scheduleLocationPull, scheduleLocationPullTimeout) + this.locationTimeout = setTimeout( + this.scheduleLocationPull, + scheduleLocationPullTimeout + ) } async getTripsEndpoint(