Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Last active January 19, 2020 16:14
Show Gist options
  • Save theburningmonk/9170c1c8f8fbc7fae5e351da359f2cb5 to your computer and use it in GitHub Desktop.
Save theburningmonk/9170c1c8f8fbc7fae5e351da359f2cb5 to your computer and use it in GitHub Desktop.
module.exports.handler = (event, context, callback) => {
let position = event.position || 0;
do {
... // process the tasks in small batches that can be completed in, say, less than 10s
// when there's less than 10s left, stop
} while (position < totalTaskCount && context.getRemainingTimeInMillis() > 10000);
if (position < totalTaskCount) {
let newEvent = Object.assign(event, { position });
recurse(newEvent);
callback(null, `to be continued from [${position}]`);
} else {
callback(null, "all done");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment