Skip to content

Commit 89a87b1

Browse files
author
sachin-maheshwari
authored
Merge pull request #219 from topcoder-platform/Issue_218
Debug update challenge id script
2 parents 82ee6ee + 2fd86b5 commit 89a87b1

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

scripts/updateToV5ChallengeId.js

Lines changed: 19 additions & 5 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,7 +52,8 @@ 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
}
@@ -55,7 +64,7 @@ function * updateRecords () {
5564
logger.debug(`Number of ${tableName}s fetched from DB - ${totalRecords}. More fetch iterations may follow (pagination in progress)`)
5665
for (let i = 0; i < totalRecords; i++) {
5766
const record = records.Items[i]
58-
promises.push(updateRecord(record))
67+
promises.push(updateRecord(record, failedRecords))
5968
}
6069
// Continue fetching the remaining records from Database
6170
if (typeof records.LastEvaluatedKey !== 'undefined') {
@@ -69,6 +78,11 @@ function * updateRecords () {
6978
for (const rs of paraRecords) {
7079
yield rs
7180
}
81+
logger.info(`Processed ${promises.length - failedRecords.length} records successfully`)
82+
if (failedRecords.length > 0) {
83+
logger.warn(`Processing of ${failedRecords.length} records failed`)
84+
logger.info(`Failed records: ${_.join(_.map(failedRecords, f => JSON.stringify(_.pick(f, ['id', 'challengeId'])), ','))}`)
85+
}
7286
}
7387

7488
co(function * () {

0 commit comments

Comments
 (0)