Add campaign manager
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
using Hcs.Broker;
|
||||
using Hcs.Broker.Logger;
|
||||
using Hcs.Broker.MessageCapturer;
|
||||
using Hcs.WebApp.BackgroundServices.Executors;
|
||||
using Hcs.WebApp.BackgroundServices.OperationExecutors;
|
||||
using Hcs.WebApp.Config;
|
||||
using Hcs.WebApp.Services;
|
||||
|
||||
@ -26,12 +26,14 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
InitializeClient();
|
||||
|
||||
var scope = scopeFactory.CreateScope();
|
||||
var operationService = scope.ServiceProvider.GetRequiredService<OperationService>();
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
while (state.TryDequeueOperation(out var operation))
|
||||
{
|
||||
if (stoppingToken.IsCancellationRequested) return;
|
||||
|
||||
var messageGuid = string.Empty;
|
||||
try
|
||||
{
|
||||
@ -40,12 +42,13 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Добавить таймауты и макс количество попыток выполнения операции
|
||||
state.EnqueueOperation(operation);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(messageGuid))
|
||||
{
|
||||
await operationService.SetOperationMessageGuidAsync(operation.Id, messageGuid);
|
||||
await headquartersService.SetOperationMessageGuidAsync(operation.Id, messageGuid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,9 +59,9 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
private async Task InitializeStateAsync()
|
||||
{
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
var operationService = scope.ServiceProvider.GetRequiredService<OperationService>();
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
|
||||
var operations = await operationService.GetInitiatedOperationsAsync();
|
||||
var operations = await headquartersService.GetInitiatedOperationsAsync();
|
||||
foreach (var operation in operations)
|
||||
{
|
||||
state.EnqueueOperation(operation);
|
||||
|
||||
Reference in New Issue
Block a user