Skip to content

Instantly share code, notes, and snippets.

@syrnick
Created May 11, 2018 00:15
Show Gist options
  • Save syrnick/cc912ee9314389af4bb9678da7f4e743 to your computer and use it in GitHub Desktop.
Save syrnick/cc912ee9314389af4bb9678da7f4e743 to your computer and use it in GitHub Desktop.
Test timers lambda
var lastRun = new Date();
var numFailed = 0;
var numUpdatedTime = 0;
var numChecked = 0;
var numFatalFailures = 0;
setInterval(() => {
numUpdatedTime++;
console.log('---------- Update time', new Date().toJSON());
lastRun = new Date();
}, 5000);
setInterval(() => {
numChecked++;
if (new Date() - lastRun > 5000) {
console.log(' check failed', new Date().toJSON());
numFailed ++;
} else {
console.log(' check passed', new Date().toJSON());
numFailed = 0;
}
if (numFailed >= 5) {
numFatalFailures++;
}
}, 200);
exports.handler = async (event) => {
const response = {
numChecked,
numUpdatedTime,
numFailed,
numFatalFailures,
};
return JSON.stringify(response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment