Wait other states in campaign management service
This commit is contained in:
@ -5,19 +5,25 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public class CampaignManagementService(
|
||||
CampaignManagementState campaignManagementState,
|
||||
OperationExecutionState operationExecutionState,
|
||||
ResultWaitState resultWaitState,
|
||||
ManagerFactory managerFactory,
|
||||
IServiceScopeFactory scopeFactory) : BackgroundService
|
||||
{
|
||||
private const int STATES_WAIT_TIME = 1000;
|
||||
private const int ITERATION_TIME = 1000;
|
||||
private const int SLEEP_TIME = 30000;
|
||||
|
||||
private readonly CampaignManagementState campaignManagementState = campaignManagementState;
|
||||
private readonly OperationExecutionState operationExecutionState = operationExecutionState;
|
||||
private readonly ResultWaitState resultWaitState = resultWaitState;
|
||||
private readonly ManagerFactory managerFactory = managerFactory;
|
||||
private readonly IServiceScopeFactory scopeFactory = scopeFactory;
|
||||
private readonly List<IManager> managers = [];
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
await WaitForOtherStates();
|
||||
await InitializeStateAsync();
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
@ -64,6 +70,14 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
}
|
||||
}
|
||||
|
||||
private async Task WaitForOtherStates()
|
||||
{
|
||||
while (!operationExecutionState.Ready || !resultWaitState.Ready)
|
||||
{
|
||||
await Task.Delay(STATES_WAIT_TIME);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InitializeStateAsync()
|
||||
{
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
|
||||
Reference in New Issue
Block a user