Created
October 20, 2016 02:52
-
-
Save cameck/e33a5e52d7dacb3455ad9e33c28fa8a5 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
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