Skip to content

Instantly share code, notes, and snippets.

@cameck
Created October 20, 2016 02:52
Show Gist options
  • Save cameck/e33a5e52d7dacb3455ad9e33c28fa8a5 to your computer and use it in GitHub Desktop.
Save cameck/e33a5e52d7dacb3455ad9e33c28fa8a5 to your computer and use it in GitHub Desktop.
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