This package provides a hosted queue service to execute background tasks in order.
The implementation is based on this documentation: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&tabs=visual-studio#queued-background-tasks
- reference this nuget package: https://www.nuget.org/packages/Samhammer.QueuedHostedService/
Register the background queue service in startup:
public void ConfigureServices(IServiceCollection services)
{
services.AddBackgroundQueue();
}
Add tasks to the queue:
public class SampleService
{
private IBackgroundTaskQueue BackgroundQueue { get; }
public SampleService(IBackgroundTaskQueue backgroundQueue)
{
BackgroundQueue = backgroundQueue;
}
public SampleMethod() {
BackgroundQueue.Enqueue(cancellationToken =>
{
Console.WriteLine("Executing background task.");
return Task.CompletedTask;
});
}
}
- Create a tag and let the github action do the publishing for you