Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/samhammerag/samhammer.queuedhostedservice

hostedservice to execute background tasks in order
https://github.com/samhammerag/samhammer.queuedhostedservice

net-core-project-lib

Last synced: about 1 month ago
JSON representation

hostedservice to execute background tasks in order

Awesome Lists containing this project

README

        

## Samhammer.QueuedHostedService

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

#### How to add this to your project:
- reference this nuget package: https://www.nuget.org/packages/Samhammer.QueuedHostedService/

#### How to use:

Register the background queue service in startup:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddBackgroundQueue();
}
```

Add tasks to the queue:
```csharp
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;
});
}
}
```

## Contribute

#### How to publish a nuget package
- Create a tag and let the github action do the publishing for you