Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROD] Deduplicate program personnel coming in from HSES. #2368

Merged
merged 7 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
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
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);
}
})();