Refactor campaign manager
This commit is contained in:
@ -3,24 +3,30 @@ using Hcs.WebApp.Services;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
{
|
||||
public abstract class ManagerBase(OperationExecutionState operationExecutionState, ResultWaitState resultWaitState, Campaign campaign) : IManager
|
||||
public abstract class ManagerBase(
|
||||
IServiceScopeFactory scopeFactory,
|
||||
OperationExecutionState operationExecutionState,
|
||||
ResultWaitState resultWaitState,
|
||||
Campaign campaign) : IManager
|
||||
{
|
||||
protected readonly IServiceScope scope = scopeFactory.CreateScope();
|
||||
protected readonly OperationExecutionState operationExecutionState = operationExecutionState;
|
||||
protected readonly ResultWaitState resultWaitState = resultWaitState;
|
||||
protected readonly Campaign campaign = campaign;
|
||||
|
||||
private HeadquartersService? headquartersService;
|
||||
|
||||
protected HeadquartersService HeadquartersService => headquartersService ??= scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
|
||||
public IManager.ManagerState State { get; protected set; } = IManager.ManagerState.Created;
|
||||
|
||||
public abstract Task StartAsync(IServiceScope scope);
|
||||
public abstract Task ProcessAsync();
|
||||
|
||||
public abstract Task CheckStateAsync(IServiceScope scope);
|
||||
|
||||
public async Task EndWithFailAsync(IServiceScope scope, Exception e)
|
||||
public async Task EndWithFailAsync(Exception e)
|
||||
{
|
||||
State = IManager.ManagerState.Ended;
|
||||
await HeadquartersService.SetCampaignEndedWithFailAsync(campaign.Id, e.Message);
|
||||
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
await headquartersService.SetCampaignEndedWithFailAsync(campaign.Id, e.Message);
|
||||
State = IManager.ManagerState.Ended;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user