-
Notifications
You must be signed in to change notification settings - Fork 2
feat(router): added a simple wrapper around background tasks #452
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @dotansimha, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new framework for managing background tasks within the router application. It provides a Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a simple and effective manager for background tasks, which is a great addition for handling long-running processes tied to the server's lifecycle. The use of CancellationToken
for graceful shutdown is well-implemented. My review includes a few suggestions to enhance robustness by handling task panics, improve logging consistency, and correct a minor typo.
join_all(self.task_handles).await; | ||
|
||
println!("all background tasks have been shut down gracefully."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of improvements that can be made here:
- Handle Task Panics: The result of
join_all
is currently ignored. If a background task panics, it will result in aJoinError
which will be silently swallowed. It's important to handle these results and log any panics to aid in debugging. - Consistent Logging: The
println!
macro is used, but the rest of the project uses thetracing
crate. For consistency and to benefit from structured logging, it's better to useinfo!
.
This suggestion addresses both points.
let join_results = join_all(self.task_handles).await;
for result in join_results {
if let Err(err) = result {
error!("A background task panicked during shutdown: {:?}", err);
}
}
info!("all background tasks have been shut down gracefully.");
.map_err(|err| err.into()) | ||
.map_err(|err| err.into()); | ||
|
||
info!("server stopped, clearning background tasks"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait with merging this PR until we actually use it for something |
Can be easily used like that to create background tasks that are also linked to the lifetime of the server: