Skip to content

Commit 29b0f25

Browse files
committed
Better error messages for handling when unlock is attempted against a non-current batch. v1.1.5
1 parent ab0a495 commit 29b0f25

File tree

1 file changed

+80
-43
lines changed

1 file changed

+80
-43
lines changed

unlockBatch.js

Lines changed: 80 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,111 @@
66
http://aws.amazon.com/asl/
77
88
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and limitations under the License.
9-
*/
9+
*/
1010

1111
var aws = require('aws-sdk');
1212
require('./constants');
1313
var common = require('./common');
1414

15-
if (process.argv.length < 4) {
16-
console.log("You must provide an AWS Region Code, Batch ID, and configured Input Location to use Unlock");
15+
var usage = function() {
16+
console.log("You must provide an AWS Region Code, Batch ID, and configured Input Location to use Unlock.");
1717
process.exit(ERROR);
1818
}
19+
20+
if (process.argv.length < 4) {
21+
usage();
22+
}
23+
1924
var setRegion = process.argv[2];
2025
var thisBatchId = process.argv[3];
2126
var prefix = process.argv[4];
2227

28+
if (!thisBatchId || !prefix) {
29+
usage();
30+
}
2331
var dynamoDB = new aws.DynamoDB({
2432
apiVersion : '2012-08-10',
2533
region : setRegion
2634
});
2735

28-
var updateBatchStatus = {
36+
var getConfig = {
2937
Key : {
30-
batchId : {
31-
S : thisBatchId,
32-
},
3338
s3Prefix : {
3439
S : prefix
3540
}
3641
},
37-
TableName : batchTable,
38-
AttributeUpdates : {
39-
status : {
40-
Action : 'PUT',
41-
Value : {
42-
S : 'open'
43-
}
44-
},
45-
lastUpdate : {
46-
Action : 'PUT',
47-
Value : {
48-
N : '' + common.now()
49-
}
50-
}
51-
},
52-
// the batch to be unlocked must be in locked or error state - we can't reopen
53-
// 'complete' batches
54-
Expected : {
55-
status : {
56-
AttributeValueList : [ {
57-
S : 'locked'
58-
}, {
59-
S : 'error'
60-
} ],
61-
ComparisonOperator : 'IN'
62-
}
63-
}
42+
TableName : configTable,
43+
ConsistentRead : true
6444
};
6545

66-
dynamoDB.updateItem(updateBatchStatus, function(err, data) {
46+
dynamoDB.getItem(getConfig, function(err, data) {
6747
if (err) {
68-
if (err.code === conditionCheckFailed) {
69-
console.log("Batch " + thisBatchId + " cannot be unlocked");
48+
console.log(err);
49+
process.exit(ERROR);
50+
} else {
51+
if (!data) {
52+
console.log("Unable to find Configuration with S3 Prefix " + prefix + " in Region " + setRegion);
7053
} else {
71-
console.log(err);
72-
process.exit(ERROR);
54+
// only allow unlocking if the batch is allocated as current
55+
if (data.Item.currentBatch.S !== thisBatchId) {
56+
console.log("Batch " + thisBatchId + " is not currently allocated as the open batch for Load Configuration on "
57+
+ prefix + ". Use reprocessBatch.js to rerun the load of this Batch.");
58+
process.exit(ERROR);
59+
} else {
60+
var updateBatchStatus = {
61+
Key : {
62+
batchId : {
63+
S : thisBatchId,
64+
},
65+
s3Prefix : {
66+
S : prefix
67+
}
68+
},
69+
TableName : batchTable,
70+
AttributeUpdates : {
71+
status : {
72+
Action : 'PUT',
73+
Value : {
74+
S : 'open'
75+
}
76+
},
77+
lastUpdate : {
78+
Action : 'PUT',
79+
Value : {
80+
N : '' + common.now()
81+
}
82+
}
83+
},
84+
// the batch to be unlocked must be in locked or error state - we
85+
// can't reopen
86+
// 'complete' batches
87+
Expected : {
88+
status : {
89+
AttributeValueList : [ {
90+
S : 'locked'
91+
}, {
92+
S : 'error'
93+
} ],
94+
ComparisonOperator : 'IN'
95+
}
96+
}
97+
};
98+
99+
dynamoDB.updateItem(updateBatchStatus, function(err, data) {
100+
if (err) {
101+
if (err.code === conditionCheckFailed) {
102+
console.log("Batch " + thisBatchId + " cannot be unlocked as it is not in 'locked' or 'error' status");
103+
} else {
104+
console.log(err);
105+
process.exit(ERROR);
106+
}
107+
} else {
108+
console.log("Batch " + thisBatchId + " Unlocked and ready for reprocessing");
109+
}
110+
111+
process.exit(OK);
112+
});
113+
}
73114
}
74-
} else {
75-
console.log("Batch " + thisBatchId + " Unlocked and ready for reprocessing");
76115
}
77-
78-
process.exit(OK);
79116
});

0 commit comments

Comments
 (0)