feat(nextRunWorker): добавлен еще один backgroundWorker, который смотрит очередь, и пересчитывает nextRun для jobGroupId

This commit is contained in:
Mikhail Trubnikov
2026-02-27 14:05:25 +10:00
parent f7a2170454
commit 10bf68709b
16 changed files with 319 additions and 33 deletions

View File

@@ -0,0 +1,22 @@
using PARR.NextRun;
namespace PARR.NextRunWorker
{
public class IntervalWorker : BackgroundService
{
private readonly INextRunIntervalService nextRunIntervalService;
private readonly ILogger<IntervalWorker> logger;
public IntervalWorker(INextRunIntervalService nextRunIntervalService, ILogger<IntervalWorker> logger)
{
this.nextRunIntervalService = nextRunIntervalService;
this.logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
logger.LogInformation("Запуск {workerName}", nameof(IntervalWorker));
await nextRunIntervalService.StartAsync();
}
}
}

View File

@@ -25,7 +25,25 @@ builder.Services.InstallNextRunServices(builder.Configuration);
builder.Configuration.AddNextRunConfigurations(builder.Services);
builder.Services.AddNextRunSettings(builder.Configuration);
builder.Services.AddHostedService<Worker>();
// Задается через переменные окружеия
var runRabbit = builder.Configuration.GetValue<bool>("ENABLE_RABBIT", true);
var runInterval = builder.Configuration.GetValue<bool>("ENABLE_INTERVAL", true);
if (runRabbit)
{
builder.Services.AddHostedService<RabbitWorker>();
}
if (runInterval)
{
builder.Services.AddHostedService<IntervalWorker>();
}
// Настройка краша при ошибке. Если хоть один из воркеров упадет, то падает целиком проект
builder.Services.Configure<HostOptions>(options =>
{
options.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.StopHost;
});
var host = builder.Build();
host.Run();

View File

@@ -0,0 +1,28 @@
using PARR.NextRun;
namespace PARR.NextRunWorker
{
public class RabbitWorker : BackgroundService
{
private readonly INextRunRabbitService nextRunRabbitService;
private readonly ILogger<RabbitWorker> logger;
public RabbitWorker(INextRunRabbitService nextRunRabbitService, ILogger<RabbitWorker> logger)
{
this.nextRunRabbitService = nextRunRabbitService;
this.logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
logger.LogInformation("Запуск {workerName}", nameof(RabbitWorker));
await nextRunRabbitService.StopAsync();
}
public override Task StopAsync(CancellationToken cancellationToken)
{
nextRunRabbitService.StopAsync().Wait();
return base.StopAsync(cancellationToken);
}
}
}

View File

@@ -1,19 +0,0 @@
using PARR.NextRun;
namespace PARR.NextRunWorker
{
public class Worker : BackgroundService
{
private readonly INextRunManager nextRunManager;
public Worker(INextRunManager nextRunManager)
{
this.nextRunManager = nextRunManager;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await nextRunManager.StartAsync();
}
}
}

View File

@@ -25,5 +25,10 @@
}
}
]
},
"WorkerSettings": {
"MqSettings": {
"HostName": "10.99.253.216"
}
}
}

View File

@@ -22,7 +22,14 @@
}
}
},
"WorkerSettings": {
"RepeatEvery": "0:50:00"
"WorkerSettings": {
"RepeatEvery": "0:50:00",
"MqSettings": {
"HostName": "parr-rabbitmq",
"QueueName": "parr-next-run-updater",
"User": "next_run_updater_reader",
"Password": "LJFgsifgFidfsdvi123#!23",
"PrefetchCount": 100
}
}
}