-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use ntp time to avoid issues with local clock drift and watchStack
It would previously skip events and hang waiting for a terminal status if the local clock had drifted ahead of AWS. This is probably just a stop-gap and I will refactor this further to use previous stack events or the CreationTimestamp as the startTime marker rather than calling out to ntp.
- Loading branch information
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { logger } from './logger'; | ||
import * as Promise from 'bluebird'; | ||
|
||
let ntpClient: any; | ||
ntpClient = require('ntp-client'); | ||
ntpClient.ntpReplyTimeout = 2000; | ||
type _getNetworkTime = (server: string, port: number, callback: (err: any, ts:Date)=> void) => void; | ||
let _getNetworkTime: _getNetworkTime; | ||
_getNetworkTime = ntpClient.getNetworkTime; | ||
const getNetworkTime = Promise.promisify(_getNetworkTime); | ||
|
||
const getReliableTime = (): Promise<Date> => | ||
getNetworkTime("pool.ntp.org", 123) | ||
.catch((e) => { | ||
logger.info('error in getNetworkTime. Retrying', e=e) | ||
return getNetworkTime("pool.ntp.org", 123) | ||
}).catch((e) => { | ||
logger.info('error in getNetworkTime. Falling back to new Date()', e=e) | ||
return new Date(); | ||
}); | ||
|
||
export default getReliableTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters