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

#3666 - Queue Monitoring - Default Queue Error Handling #4020

Merged
merged 6 commits into from
Dec 3, 2024

Conversation

andrewsignori-aot
Copy link
Collaborator

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

This PR is a proposal to unify the queue behavior. It contains changes for start and cancel assessments regular queues and the idea is to expand it to all schedulers.

The below image shows these points to be shared and forced for all the queues, using the CAS scheduler as an example.
1 - Return type;
2 - Provide a processSummary;
3 - try/catch and default start message.
4 - Error check on processSummary to force the jobs to fail.
5 - Error handling on catch.
6 - Final log activities during finally.
image
Note: The above will also ensure the E2E tests follow a closer approach.

Sample log for a queue using the new BaseQueue<T> class.

image

Side effects

The idea is to have the BaseScheduler extend the BaseQueue which will force a change in every single scheduler (which would be the idea). To avoid the need to change every single scheduler and adapt every E2E, the methods required by BaseQueue can be implemented temporarily as below. The idea is to start the scheduler refactor still during this ticket.

/**
 * To be implemented.
 */
processQueue(_job: Job<void>): Promise<string | string[]> {
  throw new Error("Method not implemented.");
}

/**
 * To be implemented.
 */
async process(
  _job: Job<void>,
  _processSummary: ProcessSummary,
): Promise<string | string[]> {
  throw new Error("Method not implemented.");
}

Error Fix

Fixed an issue with the logger service where null message was logged right after the regular message.

@andrewsignori-aot andrewsignori-aot marked this pull request as ready for review December 3, 2024 18:08
@andrewsignori-aot andrewsignori-aot changed the title #3666 - Added base queue #3666 - Queue Monitoring - Default Queue Error Handling Dec 3, 2024
@dheepak-aot dheepak-aot self-requested a review December 3, 2024 20:06
@andrepestana-aot andrepestana-aot self-requested a review December 3, 2024 21:21
const result = await this.process(job, processSummary);
processSummary.info(`${job.queue.name}, job ID ${job.id}, executed.`);
const logsSum = processSummary.getLogLevelSum();
if (logsSum.error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

With logSum errors now certainly resulting in retry(being thrown) we should have a clear understanding with the team about when to use warning and error messages.

/**
* Provides basic functionality for queue processing.
*/
export abstract class BaseQueue<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's good to have it in a abstract class. We can even have the logging for the job initialization and job ending in abstract methods if we that level of customization for some process. Good idea!

async processQueue(job: Job<T>): Promise<string | string[]> {
const processSummary = new ProcessSummary();
try {
this.logger.log(`Processing queue ${job.queue.name}, job ID ${job.id}.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great initiative to centralize the common logic. ❤️

workflowName,
job.data.assessmentId,
);
return "Workflow call executed with success.";
}

@InjectLogger()
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 the logger is not required here anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The logger should be added to every processor to ensure the right context is set (it is done during the property injection). Not having it causes the logs to be set to the base class context. We have many schedulers right now with this issue.

"No impacts were detected on future applications.",
);
}
}
await summary.info("Assessment cancelled with success.");
return summary.getSummary();
return "Assessment cancelled with success.";
});
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same with removing logger 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.

Please check #4020 (comment)

Copy link
Collaborator

@andrepestana-aot andrepestana-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. It will be very beneficial to the project and can be done in parts so I think we can at least start it in this sprint.

Copy link

sonarqubecloud bot commented Dec 3, 2024

Copy link

github-actions bot commented Dec 3, 2024

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 21.96% ( 3742 / 17040 )
Methods: 10.07% ( 214 / 2125 )
Lines: 25.29% ( 3250 / 12849 )
Branches: 13.46% ( 278 / 2066 )

Copy link

github-actions bot commented Dec 3, 2024

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

github-actions bot commented Dec 3, 2024

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 83.78% ( 1307 / 1560 )
Methods: 81.76% ( 130 / 159 )
Lines: 85.27% ( 1106 / 1297 )
Branches: 68.27% ( 71 / 104 )

Copy link

github-actions bot commented Dec 3, 2024

E2E SIMS API Coverage Report

Totals Coverage
Statements: 67.17% ( 5844 / 8700 )
Methods: 64.86% ( 720 / 1110 )
Lines: 71.14% ( 4592 / 6455 )
Branches: 46.87% ( 532 / 1135 )

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.

Great work and thanks for brining this organization of things that are done in Queue processors. Looks good 👍

@andrewsignori-aot andrewsignori-aot added this pull request to the merge queue Dec 3, 2024
Merged via the queue into main with commit b71d175 Dec 3, 2024
21 checks passed
@andrewsignori-aot andrewsignori-aot deleted the feature/#3666-fail-jobs-on-exception branch December 4, 2024 20:57
andrewsignori-aot added a commit that referenced this pull request Dec 12, 2024
- Extended the `BaseScheduler` from the `BaseQueue` to enforce all the
same basic features like `porcessSummary` and error handling, as agreed
during PR #4020.
- Started the refactor os some scheduler to be used as a baseline for
the upcoming refactors.
  - cas-supplier-integration.scheduler.ts
  - cra-process-integration.scheduler.ts
  - cra-response-integration.scheduler.ts

- Added the below code to every scheduler to be refactored.
_Note:_ **this is also responsible for the Sonarcloud duplication
issue.** **There are 23 files that have exactly the same change.**
```ts
/**
 * To be removed once the method {@link process} is implemented.
 * This method "hides" the {@link Process} decorator from the base class.
 */
async processQueue(): Promise<string | string[]> {
  throw new Error("Method not implemented.");
}

/**
 * When implemented in a derived class, process the queue job.
 * To be implemented.
 */
protected async process(): Promise<string | string[]> {
  throw new Error("Method not implemented.");
}
```
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