exports.resetBatchMarker = function()

in resetCurrentBatch.js [79:152]


exports.resetBatchMarker = function (prefix, setRegion, currentBatchId, callback) {
    var getConfig = {
        Key: {
            s3Prefix: {
                S: prefix
            }
        },
        TableName: configTable,
        ConsistentRead: true
    };

    dynamoDB.getItem(getConfig, function (err, data) {
        if (err) {
            console.log(err);
            process.exit(ERROR);
        } else {
            if (!data || !data.Item || !data.Item.currentBatch) {
                console.log("Unable to find Configuration with S3 Prefix " + prefix + " in Region " + setRegion);
            } else {
                // update the current batch entry to a new marker value
                if (data.Item.currentBatch.S !== currentBatchId) {
                    console.log("Batch " + currentBatchId + " is not currently allocated as the open batch for Load Configuration on " + prefix
                        + ". Something has probably changed automatically, so we can't proceed.");
                    process.exit(ERROR);
                } else {
                    var newBatchId = uuid.v4();

                    var resetBatchParam = {
                        Key: {
                            s3Prefix: {
                                S: prefix
                            }
                        },
                        TableName: configTable,
                        AttributeUpdates: {
                            currentBatch: {
                                Action: 'PUT',
                                Value: {
                                    S: newBatchId
                                }
                            },
                            lastUpdate: {
                                Action: 'PUT',
                                Value: {
                                    N: '' + common.now()
                                }
                            },
                            status: {
                                Action: 'PUT',
                                Value: {
                                    S: open
                                }
                            }
                        }
                    };

                    dynamoDB.updateItem(resetBatchParam, function (err, data) {
                        if (err) {
                            if (err.code === conditionCheckFailed) {
                                console.log("Batch " + currentBatchId + " cannot be modified as the status is currently 'open' or 'complete' status");
                            } else {
                                console.log(err);
                                callback(err)
                            }
                        } else {
                            console.log("Batch " + currentBatchId + " rotated to value " + newBatchId + " and is ready for use");
                        }
                        callback();
                    });
                }
            }
        }
    });
}