Fix some stuff
This commit is contained in:
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,12 +88,10 @@
|
||||
{
|
||||
finalState = CommonPageState.OperationWaiting;
|
||||
}
|
||||
else
|
||||
{
|
||||
registries = await RegistryService.GetAllRegistriesAsync(true);
|
||||
}
|
||||
|
||||
CampaignManagementState.OnCampaignStarted += OnCampaignStarted;
|
||||
CampaignManagementState.OnCampaignCreated += OnCampaignCreated;
|
||||
|
||||
registries = await RegistryService.GetAllRegistriesAsync(true);
|
||||
}
|
||||
|
||||
ChangeState(finalState);
|
||||
@ -162,7 +160,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
void OnCampaignStarted(Campaign campaign)
|
||||
void OnCampaignCreated(Campaign campaign)
|
||||
{
|
||||
if (campaign.Type == Campaign.CampaignType.ExportCommonRegistryElements_15_7_0_1)
|
||||
{
|
||||
@ -172,6 +170,6 @@
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
CampaignManagementState.OnCampaignStarted -= OnCampaignStarted;
|
||||
CampaignManagementState.OnCampaignCreated -= OnCampaignCreated;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ namespace Hcs.WebApp.Services
|
||||
return await context.Operations.CountAsync(x => x.CampaignId == campaignId && !x.EndedAt.HasValue) > 0;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Campaign>> GetInitiatedCampaignAsync()
|
||||
public async Task<IEnumerable<Campaign>> GetNotEndedCampaignsAsync()
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
return await (from campaign in context.Campaigns
|
||||
@ -29,7 +29,7 @@ namespace Hcs.WebApp.Services
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
return await (from operation in context.Operations
|
||||
where !operation.EndedAt.HasValue && string.IsNullOrEmpty(operation.MessageGuid)
|
||||
where string.IsNullOrEmpty(operation.MessageGuid)
|
||||
select operation).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user