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

Feature/gap 2152 v2 notifications service #59

Merged
merged 71 commits into from
Oct 26, 2023

Conversation

john-tco
Copy link
Contributor

@john-tco john-tco commented Oct 19, 2023

GAP-2152

related prs: cabinetoffice/gap-find-web#45, cabinetoffice/gap-user-service#135

@john-tco john-tco changed the base branch from develop to main October 24, 2023 16:14
@john-tco john-tco changed the base branch from main to develop October 24, 2023 16:14
Comment on lines 177 to 186
console.log(`Number of emails sent: ${notifications.length}`);
await this.savedSearchNotificationService.deleteSentSavedSearchNotifications();
console.log(
`saved search notifications temp table has been cleared`,
);
console.log(
`Task took ${
performance.now() - startTime
} milliseconds to run \r\n`,
);
Copy link
Contributor

@dominicwest dominicwest Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these logs will be really unclear when debugging in AWS

  1. Its logging inside of a loop so will be spammy/unclear
  2. Doesn't reference the scheduled job its running under
  3. saved search notifications temp table has been cleared doesn't feel significant enough to log unless of course theres an error

Comment on lines +20 to +36
const CRON_JOB_MAP = {
[ScheduledJobType.GRANT_UPDATED]:
this.v2GrantService.processGrantUpdatedNotifications,
[ScheduledJobType.GRANT_UPCOMING]:
this.v2GrantService.processGrantUpcomingNotifications,
[ScheduledJobType.NEW_GRANTS]:
this.v2GrantService.processNewGrantsNotifications,
[ScheduledJobType.SAVED_SEARCH_MATCHES]:
this.v2SavedSearchService.processSavedSearchMatches,
[ScheduledJobType.SAVED_SEARCH_MATCHES_NOTIFICATION]:
this.v2SavedSearchService
.processSavedSearchMatchesNotifications,
};
const cronFn = CRON_JOB_MAP[type as keyof typeof CRON_JOB_MAP];
const cronJob = getCronJob(cronFn, timer);
this.schedularRegistry.addCronJob(`${type}_${index}`, cronJob);
cronJob.start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first this confused me, but now I understand it love this refactor 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty :-)

Comment on lines 141 to 151
console.log(
`Number of saved saved searches to process: ${
savedSearches ? savedSearches.length : 0
}`,
);
console.log(
`Number of saved search notifications created: ${numberOfSearchesWithMatches}`,
);
console.log(
`Task took ${endTime - startTime} milliseconds to run \r\n`,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would ideally reference the scheduled job in each log, easy for them to get lost amongst other things happening concurrently in prod

}
}

await this.contentfulService.updateEntries(grantIds, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function makes a lot of logs, would get rid of it logging the whole contentful entry and make it a bit clearer what its doing. Again, reference the scheduled job its running under in the logs

Copy link
Contributor

@dominicwest dominicwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment in general - for all logs related to these jobs, reference the job name its running under. And some additional logs around numbers affected and things like that would be ideal. There's a couple excessive logs too that output a whole contentful blob which is not ideal. Appreciate a lot of this was copy and paste, but lets improve things so its easier to debug if anything goes wrong

Copy link
Contributor

@dominicwest dominicwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also noticed we don't await the response for some sending of the emails, I know this isnt due to your PR, but this has caused performance issues for another job before. Lets prevent this now and add an await before any invocation of sendEmail

Copy link
Contributor

@dominicwest dominicwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saved search scheduled jobs fail locally for me, I believe this is because of the cron jobs ive set them to run at and that this was a bug before. But ideally it shouldn't be so unstable. Falls over because it tries to insert a duplicate saved_search_notification before the other job clears it or something.

Copy link
Contributor

@dominicwest dominicwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class effort <3

@ryan-tco ryan-tco merged commit 13673ca into develop Oct 26, 2023
@john-tco john-tco deleted the feature/GAP-2152-v2-notifications-service branch October 26, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants