in index.js [247:306]
function checkFileProcessed(config, thisBatchId, s3Info) {
var itemEntry = s3Info.bucket + '/' + s3Info.key;
// perform the idempotency check for the file before we put it
// into a manifest
var fileEntry = {
Key: {
loadFile: {
S: itemEntry
}
},
TableName: filesTable,
ExpressionAttributeNames: {
"#rcvDate": "receiveDateTime"
},
ExpressionAttributeValues: {
":rcvDate": {
S: common.readableTime(common.now())
},
":incr": {
N: "1"
}
},
UpdateExpression: "set #rcvDate = :rcvDate add timesReceived :incr",
ReturnValues: "ALL_NEW"
};
logger.debug("Checking whether File is already processed");
logger.debug(JSON.stringify(fileEntry));
// add the file to the processed list
dynamoDB.updateItem(fileEntry, function (err, data) {
var msg;
if (err) {
msg = "Error " + err.code + " for " + fileEntry;
logger.error(msg);
context.done(error, msg);
} else {
if (!data) {
msg = "Update failed to return data from Processed File Check";
logger.error(msg);
context.done(error, msg);
} else {
if (data.Attributes.batchId && data.Attributes.batchId.S) {
// there's already a pending batch link, so this is a
// full duplicate and we'll discard
logger.info("File " + itemEntry + " Already Processed");
context.done(null, null);
} else {
// update was successful, and either this is the first
// event and there was no batch ID
// specified, or the file is a reprocess but the batch
// ID attachment didn't work - proceed
// with adding the entry to the pending batch
addFileToPendingBatch(config, thisBatchId, s3Info, itemEntry);
}
}
}
});
};