Skip to content

Instantly share code, notes, and snippets.

@alessandrobologna
Last active March 28, 2018 15:20
Show Gist options
  • Save alessandrobologna/7b7953d73844454152dd3c34a44cc080 to your computer and use it in GitHub Desktop.
Save alessandrobologna/7b7953d73844454152dd3c34a44cc080 to your computer and use it in GitHub Desktop.
/*
* 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