-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Stop IHostedService instances asynchronously by default #68216
Stop IHostedService instances asynchronously by default #68216
Conversation
Tagging subscribers to this area: @dotnet/area-extensions-hosting Issue DetailsFixes 68036
|
/// <remarks> | ||
/// Defaults to <see cref="BackgroundServiceStopBehavior.Asynchronous"/> | ||
/// </remarks> | ||
public BackgroundServiceStopBehavior BackgroundServiceStopBehavior { get; set; } = |
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.
Public API changes need to go through https://aka.ms/api-review process.
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.
We will need to add some tests for the new and old behavior.
I agree, but I just wanted to see if this solution is the route that would be preferred prior to spending time on tests.
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.
Public API changes need to go through https://aka.ms/api-review process.
It looks like the issue still needs a sponsor.
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.
Can you update the issue to follow the template?
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.
Done
We will need to add some tests for the new and old behavior. |
switch (_options.BackgroundServiceStopBehavior) | ||
{ | ||
case BackgroundServiceStopBehavior.Sequential: | ||
try |
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.
I thought about just creating a Func<Task, Task>
for handling tasks here instead of duplicating the try/catch logic, or even doing something where you add the task to the queue without starting it, but i felt like this is more easily understandable for future maintenance.
…ged mid-execution; add support for stop behavior and exception behavior to be set in config file
BackgroundServiceStopBehavior = stopBehavior; | ||
} | ||
|
||
var backgroundServiceExceptionBehavior = configuration["backgroundServiceExceptionBehavior"]; |
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.
So the reason I added these was primarily for tests - there was already a method in place to have configuration values set and for those to be honored in the test when setting up an IHost.. and i thought.. why aren't these supported?
I'm going to close this PR until we get approval for the proposed API. We can reopen it once the API is approved. See https://aka.ms/api-review#pull-requests for more info. |
Fixes #68036