Skip to content

Commit

Permalink
Merge pull request #2368 from HHS/main
Browse files Browse the repository at this point in the history
[PROD] Deduplicate program personnel coming in from HSES.
  • Loading branch information
Jones-QuarteyDana authored Sep 13, 2024
2 parents 94af81e + ef59e95 commit 213c6e8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
56 changes: 28 additions & 28 deletions src/lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// });
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/lib/updateGrantsRecipients.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
{
Expand Down
25 changes: 14 additions & 11 deletions src/tools/importGrantRecipientsCLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})();

0 comments on commit 213c6e8

Please sign in to comment.