-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
BackgroundService TaskStatus #35991
Comments
This is a good issue and ties into the improvements I'm going to make. Now I have another good reason to expose the task of the ExecuteAsync method. |
I'm frequently building queue workers on BackgroundService, and having to build the infrastructure for stop/pause/restart and status myself. Would be valuable to have some of that control/status reporting built into the framework, or at least some method of interacting with the service. |
That has to be built on top, you can't pause them or restart them. |
Is hosted service lifecycle control never going to be a feature? Felt to me as though exposing status would have necessitated some sort of stop/start control aside from restarting the entire host. Pause I can totally understand since that's pretty implementation specific. One of my specific use cases is a set of three backgroundservice that consume from a queue and feed work to each-other. Would like to be able to shut them down in a specific order on command, then potentially re-start them. Right now I can achieve that with a shared object with flags to indicate if each service should continue to do work (pause), but it felt as though having access to the state of each service and some method of triggering StopAsync and waiting for each shutdown to complete could make that simpler. That'd end up depending on having the ability to re-start at some point as well. I'd imagine that ensuring only a single instance each service was active at any time would get more difficult if this was the case. |
That’s correct it’s never going to be a feature. Any task scheduler like thing is likely to be built on top. |
Hi David @davidfowl |
Tagging subscribers to this area: @tarekgh |
Updating the top-post to make an official API proposal, and marking it ready-for-review. Exposing this Task is generally useful to a few different scenarios - ex. it is blocking #36017. |
namespace Microsoft.Extensions.Hosting
{
public abstract class BackgroundService
{
public virtual Task ExecuteTask { get; }
}
} |
Expose the task that executes the background service, so consumers can check if it is running and/or has ran to competition or faulted. Use the new ExecuteTask to log exceptions when a BackgroundService fails after await, instead of appearing to hang. Fix dotnet#35991 Fix dotnet#36017
* Expose BackgroundService.ExecuteTask Expose the task that executes the background service, so consumers can check if it is running and/or has ran to competition or faulted. Use the new ExecuteTask to log exceptions when a BackgroundService fails after await, instead of appearing to hang. Fix #35991 Fix #36017
Is your feature request related to a problem? Please describe.
As a developer I'm unable able to determine if a registered BackgroundService is running and/or has ran to competition or faulted.
Describe the solution you'd like
The based abstract class should have a TaskStatus property added which shows the status of the ExecuteAsync task.
Proposed API
Usage example
The text was updated successfully, but these errors were encountered: