Fix some stuff

This commit is contained in:
2025-10-28 16:57:25 +09:00
parent 1a097a8f7b
commit 3bd7341ecc
6 changed files with 19 additions and 26 deletions

View File

@ -65,7 +65,7 @@ namespace Hcs.WebApp.BackgroundServices
using var scope = scopeFactory.CreateScope();
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
var campaigns = await headquartersService.GetInitiatedCampaignAsync();
var campaigns = await headquartersService.GetNotEndedCampaignsAsync();
foreach (var campaign in campaigns)
{
campaignManagementState.EnqueueCampaign(campaign);

View File

@ -7,21 +7,18 @@ namespace Hcs.WebApp.BackgroundServices
{
private readonly ConcurrentQueue<Campaign> campaigns = new();
public event Action<Campaign> OnCampaignStarted;
public event Action<Campaign> OnCampaignCreated;
public void EnqueueCampaign(Campaign campaign)
{
campaigns.Enqueue(campaign);
OnCampaignCreated?.Invoke(campaign);
}
public bool TryDequeueCampaign(out Campaign campaign)
{
return campaigns.TryDequeue(out campaign);
}
public void InvokeOnCampaignStarted(Campaign campaign)
{
OnCampaignStarted?.Invoke(campaign);
}
}
}

View File

@ -7,7 +7,12 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
{
public override async Task StartAsync(IServiceScope scope)
{
if (campaign.Step > 0) return;
if (campaign.StartedAt.HasValue)
{
State = IManager.ManagerState.Started;
return;
}
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
var registryService = scope.ServiceProvider.GetRequiredService<RegistryService>();
@ -49,9 +54,9 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
var hasActiveOperations = await headquartersService.HasActiveOperationsAsync(campaign.Id);
if (!hasActiveOperations)
{
State = IManager.ManagerState.Ended;
await headquartersService.SetCampaignEndedAsync(campaign.Id);
State = IManager.ManagerState.Ended;
}
}
}

View File

@ -7,8 +7,6 @@ namespace Hcs.WebApp.BackgroundServices
{
private readonly ConcurrentQueue<Operation> operations = new();
public event Action<Operation> OnOperationStarted;
public void EnqueueOperation(Operation operation)
{
operations.Enqueue(operation);
@ -18,10 +16,5 @@ namespace Hcs.WebApp.BackgroundServices
{
return operations.TryDequeue(out operation);
}
public void InvokeOnOperationStarted(Operation operation)
{
OnOperationStarted?.Invoke(operation);
}
}
}