37 lines
1011 B
C#
37 lines
1011 B
C#
using Hcs.WebApp.Data.Hcs;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace Hcs.WebApp.BackgroundServices
|
|
{
|
|
public class ResultWaitState
|
|
{
|
|
private readonly ConcurrentQueue<Operation> operationsInQueue = new();
|
|
private readonly HashSet<Operation> operationsInProcess = [];
|
|
|
|
public void EnqueueOperation(Operation operation)
|
|
{
|
|
operationsInQueue.Enqueue(operation);
|
|
}
|
|
|
|
public bool TryDequeueOperation(out Operation operation)
|
|
{
|
|
return operationsInQueue.TryDequeue(out operation);
|
|
}
|
|
|
|
public void SetProcessingOperation(Operation operation)
|
|
{
|
|
operationsInProcess.Add(operation);
|
|
}
|
|
|
|
public void UnsetProcessingOperation(Operation operation)
|
|
{
|
|
operationsInProcess.Remove(operation);
|
|
}
|
|
|
|
public bool HasCampaignOperation(int campaignId)
|
|
{
|
|
return operationsInProcess.Any(x => x.CampaignId == campaignId);
|
|
}
|
|
}
|
|
}
|