diff --git a/.circleci/config.yml b/.circleci/config.yml index d1e51caade..276daf47c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -563,7 +563,7 @@ parameters: default: "al-ttahub-3196-new-tr-views" type: string sandbox_git_branch: # change to feature branch to test deployment - default: "kw-escape-quotes-in-pr-title" + default: "kw-fix-duplicate-programs" type: string prod_new_relic_app_id: default: "877570491" diff --git a/src/lib/queue.js b/src/lib/queue.js index b4b3721520..b2d08869c4 100644 --- a/src/lib/queue.js +++ b/src/lib/queue.js @@ -98,46 +98,46 @@ function removeQueueEventHandlers( // Define the handlers so they can be added and removed function handleShutdown(queue) { return () => { - auditLogger.error('Shutting down, closing queue...'); - queue.close().then(() => { - auditLogger.error('Queue closed successfully.'); - removeQueueEventHandlers(queue); - process.exit(0); - }).catch((err) => { - auditLogger.error('Failed to close the queue:', err); - removeQueueEventHandlers(queue); - process.exit(1); - }); + auditLogger.error('Shutting down, but queue closing is disabled for now...'); + // queue.close().then(() => { + // auditLogger.error('Queue closed successfully.'); + // removeQueueEventHandlers(queue); + // process.exit(0); + // }).catch((err) => { + // auditLogger.error('Failed to close the queue:', err); + // removeQueueEventHandlers(queue); + // process.exit(1); + // }); }; } function handleException(queue) { return (err) => { auditLogger.error('Uncaught exception:', err); - queue.close().then(() => { - auditLogger.error('Queue closed after uncaught exception.'); - removeQueueEventHandlers(queue); - process.exit(1); - }).catch((closeErr) => { - auditLogger.error('Failed to close the queue after uncaught exception:', closeErr); - removeQueueEventHandlers(queue); - process.exit(1); - }); + // queue.close().then(() => { + // auditLogger.error('Queue closed after uncaught exception.'); + // removeQueueEventHandlers(queue); + // process.exit(1); + // }).catch((closeErr) => { + // auditLogger.error('Failed to close the queue after uncaught exception:', closeErr); + // removeQueueEventHandlers(queue); + // process.exit(1); + // }); }; } function handleRejection(queue) { return (reason, promise) => { auditLogger.error('Unhandled rejection at:', promise, 'reason:', reason); - queue.close().then(() => { - auditLogger.error('Queue closed after unhandled rejection.'); - removeQueueEventHandlers(queue); - process.exit(1); - }).catch((closeErr) => { - auditLogger.error('Failed to close the queue after unhandled rejection:', closeErr); - removeQueueEventHandlers(queue); - process.exit(1); - }); + // queue.close().then(() => { + // auditLogger.error('Queue closed after unhandled rejection.'); + // removeQueueEventHandlers(queue); + // process.exit(1); + // }).catch((closeErr) => { + // auditLogger.error('Failed to close the queue after unhandled rejection:', closeErr); + // removeQueueEventHandlers(queue); + // process.exit(1); + // }); }; } diff --git a/src/lib/updateGrantsRecipients.js b/src/lib/updateGrantsRecipients.js index d19af58e09..254e882dd5 100644 --- a/src/lib/updateGrantsRecipients.js +++ b/src/lib/updateGrantsRecipients.js @@ -340,8 +340,13 @@ export async function processFiles(hashSumHex) { ), }))); + // Deduplicate based on 'id' + const uniqueProgramsForDb = Array.from( + new Map(programsForDb.map((item) => [item.id, item])).values(), + ); + // Extract an array of all grant personnel to update. - const programPersonnel = programsForDb.flatMap((p) => p.programPersonnel); + const programPersonnel = uniqueProgramsForDb.flatMap((p) => p.programPersonnel); // Split grants between CDI and non-CDI grants. const cdiGrants = grantsForDb.filter((g) => g.regionId === 13); @@ -400,11 +405,6 @@ export async function processFiles(hashSumHex) { await updateCDIGrantsWithOldGrantData(cdiGrantsToLink); - // Deduplicate based on 'id' - const uniqueProgramsForDb = Array.from( - new Map(programsForDb.map((item) => [item.id, item])).values(), - ); - await Program.bulkCreate( uniqueProgramsForDb, { diff --git a/src/tools/importGrantRecipientsCLI.js b/src/tools/importGrantRecipientsCLI.js index df5bd7245f..14f5a760fe 100644 --- a/src/tools/importGrantRecipientsCLI.js +++ b/src/tools/importGrantRecipientsCLI.js @@ -15,14 +15,17 @@ const { argv: { skipdownload } } = option('skipdownload', { .help() .alias('help', 'h'); -if (skipdownload) { - processFiles().catch((e) => { - auditLogger.error(e); - return process.exit(1); - }); -} else { - updateGrantsRecipients().catch((e) => { - auditLogger.error(e); - return process.exit(1); - }); -} +(async () => { + try { + if (skipdownload) { + await processFiles(); + } else { + await updateGrantsRecipients(); + } + auditLogger.info('Script completed successfully'); + process.exit(0); + } catch (e) { + auditLogger.error(`Error during script execution: ${e.message}`, e); + process.exit(1); + } +})();