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

#4076 - Queue Monitoring - Schedulers Refactor (Fed Restrictions and Receipts) #4135

Merged
merged 6 commits into from
Dec 19, 2024

Conversation

andrewsignori-aot
Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot commented Dec 18, 2024

  • Refactored schedulers disbursement-receipts-file-integration and federal-restrictions-integration.
  • Adjusted existing E2Es.
  • As agreed in previous PRs
    • moving the audit user to the service instead of the processor.
    • removing the friendly start/end logs from the processor since the BaseQueue is already logging similar start/end logs.

E2E containLogMessages changes

To allow the below check to happen the method containLogMessages was changed to check if the string "contains" a value instead of "endsWith" it. The endsWith was used to have a more precise check and remove the log initial information (e.g. context and date). Using the "contains" will still give enough assertion precision and allow inspecting errors currently serialized to a JSON.

 // Act/Assert
await expect(processor.processQueue(mockedJob.job)).rejects.toThrow(
  "One or more errors were reported during the process, please see logs for details.",
);
expect(
  mockedJob.containLogMessages([
    `Error downloading file ${expectedFileName}.`,
    "Invalid file footer.",
  ]),
).toBe(true);

@andrewsignori-aot andrewsignori-aot marked this pull request as ready for review December 18, 2024 20:09
@andrewsignori-aot andrewsignori-aot changed the title #4076 - Queue Monitoring - Schedulers Refactor (Fed Restrictions and more) #4076 - Queue Monitoring - Schedulers Refactor (Fed Restrictions and Receipts) Dec 18, 2024
@lewischen-aot lewischen-aot self-requested a review December 18, 2024 21:21
Copy link
Collaborator

@lewischen-aot lewischen-aot left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍 Thanks for refactoring this part of the schedulers.

processSummary: ProcessSummary,
): Promise<string> {
await this.disbursementReceiptProcessingService.process(processSummary);
return "Completed disbursement receipts integration.";
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

this.logger.error(error);
this.logger.error(logMessage, error);
processSummary.error(logMessage, error);
return;
Copy link
Collaborator

@dheepak-aot dheepak-aot Dec 18, 2024

Choose a reason for hiding this comment

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

Adding the return here will modify the existing behavior. i.e. if there is an error processing one or more detail record, then we skip the those one and process others. With return it will abort at first failure.

Is there a reason for making this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is changing the behavior and keeping the file on error. I will remove to short the conversation and move on with the PR but I do not recall why we chose this direction. Do you remember? If not, I will start a separate conversation with biz.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we chose this direction as each receipt record can be considered independently and processed ignoring one or more records with data errors or other errors. But I would say we should check the direction with business.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As we talked, I will check with the business and consider if we should generate the report or not.
For this ticket and this PR, I will keeping the existing behavior as suggested.

const errorMessage =
"Error while generating provincial daily disbursement CSV report file.";
this.logger.error(errorMessage, error);
processSummary.error(errorMessage, error);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the retry happen when the report generation alone fail? - let me know if I am missing something here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a reason not to retry? The import should be able to be executed twice and the report generation is part of the process, hence if it fails it would not need manual intervention.
pleas let me know if we need to discuss this further.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As we discussed, let's keep the retry to allow the report to be sent and the job auto-recover avoiding the manual intervention.

let downloadResult: FedRestrictionFileRecord[];
processSummary: ProcessSummary,
): Promise<void> {
processSummary.info(`Processing file ${remoteFilePath}.`);
this.logger.log(`Starting download of file ${remoteFilePath}.`);
Copy link
Collaborator

@dheepak-aot dheepak-aot Dec 18, 2024

Choose a reason for hiding this comment

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

#4135 (comment) also at line 109

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be clear, I did not remove them all because they were serving different purposes and I did not consider it as part of the immediate refactor. I can explain further if needed. I will remove this also.

@@ -139,7 +132,7 @@ export class FedRestrictionProcessingService {
const invalidDataMessage = restriction.getInvalidDataMessage();
if (invalidDataMessage) {
const errorMessage = `Found record with invalid data at line number ${restriction.lineNumber}: ${invalidDataMessage}`;
result.errorsSummary.push(errorMessage);
processSummary.error(errorMessage);
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't we use processSummary.warn as we are not expecting retry for invalid data in the file.?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will trigger a different conversation. Yes, we can change to warn to avoid the retry, but it also should alert the Ministry in some way. I will change to a warn to move on and discuss further with biz.

* @returns true if the log message was found. otherwise false.
*/
containLogMessage(logMessage: string): boolean {
return this.logMessages.some((message) => message.endsWith(logMessage));
return this.logMessages.some((message) => message.includes(logMessage));
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@dheepak-aot
Copy link
Collaborator

Good Job @andrewsignori-aot. Added some comments. Few of them were clarifications too.

Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 22.08% ( 3783 / 17133 )
Methods: 10.07% ( 219 / 2175 )
Lines: 25.47% ( 3278 / 12868 )
Branches: 13.68% ( 286 / 2090 )

Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 65.43% ( 583 / 891 )
Methods: 59.26% ( 64 / 108 )
Lines: 68.54% ( 464 / 677 )
Branches: 51.89% ( 55 / 106 )

Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 81.73% ( 1302 / 1593 )
Methods: 67.51% ( 133 / 197 )
Lines: 84.9% ( 1091 / 1285 )
Branches: 70.27% ( 78 / 111 )

Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 67.4% ( 5922 / 8787 )
Methods: 65.09% ( 729 / 1120 )
Lines: 71.33% ( 4647 / 6515 )
Branches: 47.4% ( 546 / 1152 )

Copy link
Collaborator

@dheepak-aot dheepak-aot left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes. Looks good 👍

@andrewsignori-aot andrewsignori-aot added this pull request to the merge queue Dec 19, 2024
Merged via the queue into main with commit 77f6d41 Dec 19, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants