Imato.Services.RegularWorker
3.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Imato.Services.RegularWorker --version 3.0.2
NuGet\Install-Package Imato.Services.RegularWorker -Version 3.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Imato.Services.RegularWorker" Version="3.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Imato.Services.RegularWorker --version 3.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Imato.Services.RegularWorker, 3.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Imato.Services.RegularWorker as a Cake Addin #addin nuget:?package=Imato.Services.RegularWorker&version=3.0.2 // Install Imato.Services.RegularWorker as a Cake Tool #tool nuget:?package=Imato.Services.RegularWorker&version=3.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Imato.Services.RegularWorker
Create long running services and workers
- Create new worker Override ExecuteAsync in RegularWorker
// Worker.cs
using Imato.Services.RegularWorker;
public class Worker : RegularWorker
{
public Worker(IServiceProvider provider) : base(provider)
{
}
// Add same work in ExecuteAsync method
public override async Task ExecuteAsync(CancellationToken token)
{
await SendHelloAsync();
}
}
- Add worker to DI Simple. All your workers started automatically.
// Program.cs
using Imato.Services.RegularWorker;
var appBuilder = Host.CreateDefaultBuilder(args);
appBuilder.ConfigureWorkers(args);
Or manualy
// Program.cs
using Imato.Services.RegularWorker;
var appBuilder = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddSingleton<IHostedService, Worker>();
})
Start one worker as microservise from all your workers pool.
>myworker.exe
- Start workers
// Program.cs
using Imato.Services.RegularWorker;
var app = appBuilder.Build();
// All
app.StartAppAsync();
// Or single worker
await app.StartAppAsync(");
- Configure worker
appsettings.Example.json
{
"Workers": {
"LogWorker": {
"StartInterval": 15000,
"RunOn": "EveryWhere",
"Enabled": true
}
}
}
RunOn: PrimaryServer, SecondaryServer, SecondaryServerFirst, EveryWhere.
Or configure throw field settings in Workers DB table.
Using Log table in MS SQL server
Add configuration for DbLogger: ConnectionString, Table and table Columns
// appsettings.json
{
"ConnectionStrings": {
"mssql": "Data Source=localhost;Initial Catalog=TestDb;Persist Security Info=True;User ID=test;Password=test;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
},
"DbLogger": {
"Options": {
"ConnectionString": "Data Source=localhost;Initial Catalog=TestDb;Persist Security Info=True;User ID=test;Password=test;",
"Table": "dbo.Logs",
"Columns": "[Date], [User], [Level], [Source], [Message], [Server]"
}
}
}
}
Add logger in DI config
// Program.cs
using Imato.Services.RegularWorker;
var appBuilder = Host.CreateDefaultBuilder(args)
.ConfigureDbLogger();
.ConfigureServices(services =>
{
services.AddSingleton<IHostedService, LogWorker>();
});
// Start LogWorker and other workers
var app = appBuilder.Build();
app.StartServices();
await app.RunAsync();
or shortly configure workers
// Program.cs
using Imato.Services.RegularWorker;
var appBuilder = Host.CreateDefaultBuilder(args);
appBuilder.ConfigureWorkers();
Monitoring
View actual workers status in different apps and hosts
select id, name, host, appName, date, settings, active from dbo.workers
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Imato.Dapper.DbContext (>= 1.11.1)
- Imato.Logger.Extensions (>= 1.2.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Hosting (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.2.0 | 81 | 10/25/2024 |
3.1.1 | 80 | 10/15/2024 |
3.0.2 | 101 | 8/29/2024 |
3.0.0 | 111 | 6/21/2024 |
2.18.0 | 88 | 5/15/2024 |
2.17.4 | 144 | 3/6/2024 |
2.17.3 | 167 | 1/25/2024 |
2.17.2 | 101 | 1/24/2024 |
2.17.1 | 106 | 1/23/2024 |
2.17.0 | 125 | 1/17/2024 |
2.16.9 | 168 | 12/28/2023 |
2.16.8 | 140 | 12/28/2023 |
2.16.6 | 137 | 12/28/2023 |
2.16.5 | 122 | 12/28/2023 |
2.16.4 | 136 | 12/27/2023 |
2.16.0 | 117 | 12/20/2023 |
2.15.0 | 113 | 12/19/2023 |
2.14.0 | 124 | 12/18/2023 |
2.13.0 | 181 | 11/28/2023 |
2.12.2 | 173 | 10/18/2023 |
2.12.1 | 150 | 10/18/2023 |
2.12.0 | 143 | 9/22/2023 |
2.11.0 | 149 | 9/15/2023 |
2.10.0 | 182 | 6/7/2023 |
2.9.2 | 165 | 6/1/2023 |
2.9.1 | 163 | 6/1/2023 |
2.9.0 | 182 | 6/1/2023 |
2.6.0 | 137 | 5/22/2023 |
2.5.2 | 268 | 3/23/2023 |
2.5.1 | 259 | 2/27/2023 |
2.5.0 | 285 | 1/12/2023 |
2.4.2 | 347 | 12/26/2022 |
2.4.0 | 331 | 12/19/2022 |
2.2.1 | 331 | 12/12/2022 |
2.1.1 | 345 | 11/23/2022 |
2.1.0 | 335 | 11/23/2022 |
2.0.0 | 412 | 9/23/2022 |
1.1.0 | 433 | 8/17/2022 |
1.0.0 | 404 | 8/10/2022 |
Ready to use