Skip to content

Commit

Permalink
Fix Auckland Realtime Regression
Browse files Browse the repository at this point in the history
  • Loading branch information
consindo committed Jul 8, 2019
1 parent c22b23f commit 4b4aabf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/waka-orchestrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/waka-worker/realtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BaseRealtime, WakaRequest } from '../../typings'

const regions = {
'au-syd': RealtimeAUSYD,
// 'nz-akl': RealtimeNZAKL,
'nz-akl': RealtimeNZAKL,
'nz-wlg': RealtimeNZWLG,
}

Expand Down
17 changes: 13 additions & 4 deletions src/waka-worker/realtime/regions/nz-akl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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(
Expand Down

0 comments on commit 4b4aabf

Please sign in to comment.