Last active
January 19, 2020 16:14
-
-
Save theburningmonk/9170c1c8f8fbc7fae5e351da359f2cb5 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
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