Skip to content

Commit 792ef76

Browse files
Debug update challenge id script
1 parent 82ee6ee commit 792ef76

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

scripts/updateToV5ChallengeId.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ const helper = require('../src/common/helper')
1212
/**
1313
* Update Submission's challenge id to v5
1414
* @param {Object} submission The submission record
15+
* @param {Array} failedContainer The failed records container
1516
* @returns {Promise}
1617
*/
17-
function * updateRecord (submission) {
18-
const v5challengeId = yield helper.getV5ChallengeId(submission.challengeId)
18+
function * updateRecord (submission, failedContainer) {
19+
let v5challengeId
20+
try {
21+
v5challengeId = yield helper.getV5ChallengeId(submission.challengeId)
22+
} catch (err) {
23+
logger.error(`fetching the details of the challenge(${submission.challengeId}) failed, ${err.message}`)
24+
failedContainer.push(submission)
25+
return
26+
}
1927
const record = {
2028
TableName: 'Submission',
2129
Key: {
@@ -29,7 +37,7 @@ function * updateRecord (submission) {
2937
}
3038
if (!v5challengeId) {
3139
logger.warn(`the challengeId: ${submission.challengeId} is not having a v5 challengeId`)
32-
40+
failedContainer.push(submission)
3341
return
3442
} else if (v5challengeId === submission.challengeId) {
3543
logger.info(`the challengeId: ${submission.challengeId} is already a v5 challengeId`)
@@ -44,18 +52,21 @@ function * updateRecord (submission) {
4452
*/
4553
function * updateRecords () {
4654
const tableName = config.SUBMISSION_TABLE_NAME
47-
let promises = []
55+
const promises = []
56+
const failedRecords = []
4857
const params = {
4958
TableName: tableName
5059
}
5160
// Process until all the records from DB is fetched
52-
while (true) {
61+
let i = 20
62+
while (i > 10) {
63+
i--
5364
const records = yield dbhelper.scanRecords(params)
5465
const totalRecords = records.Items.length
5566
logger.debug(`Number of ${tableName}s fetched from DB - ${totalRecords}. More fetch iterations may follow (pagination in progress)`)
5667
for (let i = 0; i < totalRecords; i++) {
5768
const record = records.Items[i]
58-
promises.push(updateRecord(record))
69+
promises.push(updateRecord(record, failedRecords))
5970
}
6071
// Continue fetching the remaining records from Database
6172
if (typeof records.LastEvaluatedKey !== 'undefined') {
@@ -69,6 +80,11 @@ function * updateRecords () {
6980
for (const rs of paraRecords) {
7081
yield rs
7182
}
83+
logger.info(`Processed ${promises.length - failedRecords.length} records successfully`)
84+
if (failedRecords.length > 0) {
85+
logger.warn(`Processing of ${failedRecords.length} records failed`)
86+
logger.info(`Failed records: ${_.join(_.map(failedRecords, f => JSON.stringify(_.pick(f, ['id', 'challengeId'])), ','))}`)
87+
}
7288
}
7389

7490
co(function * () {

0 commit comments

Comments
 (0)