@@ -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 */
4553function * 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
7488co ( function * ( ) {
0 commit comments