Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let count = 1;
dynamoDB.batchWriteItem(params, processItemsCallback);
function processItemsCallback(err, data) {
if (err) {
console.log(JSON.stringify(err, null, 2));
} else {
console.log("Response Data: ", JSON.stringify(data));
let itemsLost = data.UnprocessedItems;
// Check if Object size is greater than 0 so we can process missed items if needed
if (itemsLost.constructor === Object && Object.keys(itemsLost).length === 0) {
console.log("Everything made it - hurray!");
} else {
console.log("Re-sending missed items");
// Exponentially raise the backoff time
count++;
setTimeout(function(){
let params = {};
params.RequestItems = itemsLost;
dynamoDB.batchWriteItem(params, processItemsCallback);
}, 1000 * count);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment