Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions scripts/updateToV5ChallengeId.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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`)
Expand All @@ -44,7 +52,8 @@ function * updateRecord (submission) {
*/
function * updateRecords () {
const tableName = config.SUBMISSION_TABLE_NAME
let promises = []
const promises = []
const failedRecords = []
const params = {
TableName: tableName
}
Expand All @@ -55,7 +64,7 @@ function * updateRecords () {
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') {
Expand All @@ -69,6 +78,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 * () {
Expand Down