Refactor campaign manager
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user