From 792ef76d294100b21cbe9bfaef0f64cb223706fa Mon Sep 17 00:00:00 2001 From: Mithun Kamath Date: Thu, 25 Feb 2021 17:57:35 +0530 Subject: [PATCH 1/2] Debug update challenge id script --- scripts/updateToV5ChallengeId.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/updateToV5ChallengeId.js b/scripts/updateToV5ChallengeId.js index b12ace12..4bb30928 100644 --- a/scripts/updateToV5ChallengeId.js +++ b/scripts/updateToV5ChallengeId.js @@ -12,10 +12,18 @@ const helper = require('../src/common/helper') /** * Update Submission's challenge id to v5 * @param {Object} submission The submission record + * @param {Array} failedContainer The failed records container * @returns {Promise} */ -function * updateRecord (submission) { - const v5challengeId = yield helper.getV5ChallengeId(submission.challengeId) +function * updateRecord (submission, failedContainer) { + let v5challengeId + try { + v5challengeId = yield helper.getV5ChallengeId(submission.challengeId) + } catch (err) { + logger.error(`fetching the details of the challenge(${submission.challengeId}) failed, ${err.message}`) + failedContainer.push(submission) + return + } const record = { TableName: 'Submission', Key: { @@ -29,7 +37,7 @@ function * updateRecord (submission) { } if (!v5challengeId) { logger.warn(`the challengeId: ${submission.challengeId} is not having a v5 challengeId`) - + failedContainer.push(submission) return } else if (v5challengeId === submission.challengeId) { logger.info(`the challengeId: ${submission.challengeId} is already a v5 challengeId`) @@ -44,18 +52,21 @@ function * updateRecord (submission) { */ function * updateRecords () { const tableName = config.SUBMISSION_TABLE_NAME - let promises = [] + const promises = [] + const failedRecords = [] const params = { TableName: tableName } // Process until all the records from DB is fetched - while (true) { + let i = 20 + while (i > 10) { + i-- const records = yield dbhelper.scanRecords(params) const totalRecords = records.Items.length logger.debug(`Number of ${tableName}s fetched from DB - ${totalRecords}. More fetch iterations may follow (pagination in progress)`) for (let i = 0; i < totalRecords; i++) { const record = records.Items[i] - promises.push(updateRecord(record)) + promises.push(updateRecord(record, failedRecords)) } // Continue fetching the remaining records from Database if (typeof records.LastEvaluatedKey !== 'undefined') { @@ -69,6 +80,11 @@ function * updateRecords () { for (const rs of paraRecords) { yield rs } + logger.info(`Processed ${promises.length - failedRecords.length} records successfully`) + if (failedRecords.length > 0) { + logger.warn(`Processing of ${failedRecords.length} records failed`) + logger.info(`Failed records: ${_.join(_.map(failedRecords, f => JSON.stringify(_.pick(f, ['id', 'challengeId'])), ','))}`) + } } co(function * () { From 2fd86b5899c017272a2a4ab02ba3c53e0be4f488 Mon Sep 17 00:00:00 2001 From: Mithun Kamath Date: Thu, 25 Feb 2021 17:58:42 +0530 Subject: [PATCH 2/2] remove debug statements --- scripts/updateToV5ChallengeId.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/updateToV5ChallengeId.js b/scripts/updateToV5ChallengeId.js index 4bb30928..10169a87 100644 --- a/scripts/updateToV5ChallengeId.js +++ b/scripts/updateToV5ChallengeId.js @@ -58,9 +58,7 @@ function * updateRecords () { TableName: tableName } // Process until all the records from DB is fetched - let i = 20 - while (i > 10) { - i-- + while (true) { const records = yield dbhelper.scanRecords(params) const totalRecords = records.Items.length logger.debug(`Number of ${tableName}s fetched from DB - ${totalRecords}. More fetch iterations may follow (pagination in progress)`)