AugusteVN.Worker 1.1.9

dotnet add package AugusteVN.Worker --version 1.1.9
NuGet\Install-Package AugusteVN.Worker -Version 1.1.9
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="AugusteVN.Worker" Version="1.1.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AugusteVN.Worker --version 1.1.9
#r "nuget: AugusteVN.Worker, 1.1.9"
#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 AugusteVN.Worker as a Cake Addin
#addin nuget:?package=AugusteVN.Worker&version=1.1.9

// Install AugusteVN.Worker as a Cake Tool
#tool nuget:?package=AugusteVN.Worker&version=1.1.9

WorkerService

Re-usables for my multiple worker service setup that supports saving success or failure run to database.


WIP*

builder.Services
    .AddOptions<WorkerConfig>
    .BindConfiguration(nameof(WorkerConfig));

builder.Services.AddWorkerRunners(builder.Configuration, provider => provider.GetRequiredService<YourDbContext>());

// Or register separately

builder.Services.AddScoped<IWorkerDbContext>(provider => provider.GetRequiredService<YourDbContext>());

builder.Services.AddSingleton<IWorkerRunner, WorkerRunner>();
builder.Services.AddSingleton<IServiceRunner, ServiceRunner>();
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
    var delayInMinutes = new AmountOfHours {Amount = _workerConfig.DelayInHours}.ToMinutes();
    var delayInMs = delayInMinutes * 1000;
    
    var weekDays = new HashSet<DayOfWeek> {DayOfWeek.Wednesday};

    while (!stoppingToken.IsCancellationRequested)
    {
        // Create scope, treat every run cycle as a request cycle.
        using var scope = _serviceProvider.CreateScope();

        await _workerRunner.RunWorkerOnScheduleAsync(new WorkerRunSettings
        {
            ServiceProvider = scope.ServiceProvider,
            WorkerName = WorkerName,
            WeekDays = weekDays,
            FrequencyInMinutes = delayInMinutes // To make sure it doesn't run constantly on specified week days.
        }, new[]
        {
            new ServiceRunSettings
            {
                WeekDays = weekDays,
                RunnableService = _animalSummaryMailer
            },
            new ServiceRunSettings
            {
                RunnableService = _sheltersSubscribersSync
            }
        });

        await Task.Delay(delayInMs, stoppingToken);
    }
}

To see it in action: Multiple Worker Services Setup in C# .NET

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.9 151 3/16/2024
1.0.9 191 1/3/2024
1.0.8 99 12/26/2023
1.0.7 112 12/21/2023
1.0.6 95 12/21/2023
1.0.5 173 11/25/2023
1.0.4 114 11/18/2023
1.0.3 124 11/13/2023
1.0.2 95 11/4/2023
1.0.1 73 11/4/2023
1.0.0 99 11/4/2023

Update dependencies.