Refactor campaign manager

This commit is contained in:
2025-10-30 17:12:37 +09:00
parent e31a075f58
commit 9515e8080c
5 changed files with 94 additions and 92 deletions

View File

@ -26,23 +26,14 @@ namespace Hcs.WebApp.BackgroundServices
{
if (stoppingToken.IsCancellationRequested) return;
using var scope = scopeFactory.CreateScope();
var manager = managerFactory.CreateManager(campaign);
if (manager != null)
{
try
{
await manager.StartAsync(scope);
managers.Add(manager);
}
catch (Exception e)
{
await manager.EndWithFailAsync(scope, e);
}
managers.Add(manager);
}
else
{
using var scope = scopeFactory.CreateScope();
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
await headquartersService.SetCampaignEndedWithFailAsync(campaign.Id, "Не удалось найти подходящий менеджер кампании");
}
@ -50,14 +41,13 @@ namespace Hcs.WebApp.BackgroundServices
foreach (var manager in managers)
{
using var scope = scopeFactory.CreateScope();
try
{
await manager.CheckStateAsync(scope);
await manager.ProcessAsync();
}
catch (Exception e)
{
await manager.EndWithFailAsync(scope, e);
await manager.EndWithFailAsync(e);
}
}