Voyager.BackgroundWorker
1.6.1
See the version list below for details.
dotnet add package Voyager.BackgroundWorker --version 1.6.1
NuGet\Install-Package Voyager.BackgroundWorker -Version 1.6.1
<PackageReference Include="Voyager.BackgroundWorker" Version="1.6.1" />
paket add Voyager.BackgroundWorker --version 1.6.1
#r "nuget: Voyager.BackgroundWorker, 1.6.1"
// Install Voyager.BackgroundWorker as a Cake Addin #addin nuget:?package=Voyager.BackgroundWorker&version=1.6.1 // Install Voyager.BackgroundWorker as a Cake Tool #tool nuget:?package=Voyager.BackgroundWorker&version=1.6.1
Voyager.BackgroundWorker
The service continuously executes tasks based on time intervals. Protects from overlapping between new requests during the previous operation hasn't been finished. Can be configured to be triggered through http request. Can be extended for purposes to carry out customized control about exclusive executive the one task in an environment.
🏁 Getting Started
Prerequisites
The library coperate with the WebApplicationBuilder or HostApplicationBuilder. By the default, the hosts contain the required Dependency Injection.
🔧 How to start
To start using the service is required to implement the interface:
namespace Voyager.BackgroundWorker
{
public interface WorkerTask
{
void Run(CancellationToken cancellationToken);
}
}
Assume that is implemented the task:
public class MyTask : Voyager.BackgroundWorker.WorkerTask
{
public void Run(CancellationToken cancellationToken)
{
// The logic goes here!
}
}
Then service is configure by the method:
var appBuilder = Host.CreateDefaultBuilder(null);
appBuilder.ConfigureServices((services) =>
{
services.AddBackgroundWorker().AddWorker<MyTask>();
});
host = appBuilder.Build();
host.Start();
Then the service starts executing the work task with a default interval every 60 seconds.
It is possoble to change the interval by setting:
services.AddBackgroundWorker()
.AddWorker<MyTask>()
.SetTimeUpToWakeUp(300);
🔧 How to trigger the task
It is an option to configure the service process with the additional requests of processing beyond times interval.
{
var appBuilder = Host.CreateDefaultBuilder(null);
appBuilder.ConfigureServices((services) =>
{
services.AddBackgroundWorker().AddWorker<MyTask>();
});
appBuilder.ConfigureWebHostDefaults((webConfigure) =>
{
webConfigure.UseStartup<Startup>();
});
host = appBuilder.Build();
host.Start();
}
class Startup
{
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBackgroundWorker();
});
}
}
🔧 How to configure the external lock
After custom implementation the class Voyager.BackgroundWorker.ExternalLock. There is the possibility to use the logic in the service by registration through the method:
services.AddBackgroundWorker()
.AddWorker<MyTask>()
.AddExternalLock<MyLock>();
✍️ Authors
- @andrzejswistowski - Idea & work. Please let me know if you find out an error or suggestions.
🎉 Acknowledgements
- Przemysław Wróbel - for the icon.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.