Last active
March 28, 2018 15:20
-
-
Save alessandrobologna/7b7953d73844454152dd3c34a44cc080 to your computer and use it in GitHub Desktop.
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
/* | |
* Just consume events from Kinesis in a sink | |
*/ | |
const pause = parseInt(process.env.PAUSE_TIME || '0'); | |
//const pause = 0; | |
const sleep = (ms) => { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
}; | |
export const handler = async (event, context, callback) => { | |
let now = Date.now(); | |
console.log(`sinking ${event.Records.length} records`); | |
// do some busy processing with your records and then... | |
if (pause > 0) { | |
// make sure that we are not returning before pause time | |
let elapsed = Date.now() - now; | |
console.log(`sleeping ${pause * 1000 - elapsed} ms`); | |
await sleep(pause * 1000 - elapsed); | |
} | |
callback(null, 'Done'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment