Wait other states in campaign management service

This commit is contained in:
2025-11-03 11:46:58 +09:00
parent 7cfabe0af2
commit 7d375f27d6
5 changed files with 25 additions and 2 deletions

View File

@ -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();