Add dynamic operations change UI
This commit is contained in:
@ -42,16 +42,23 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
var executor = executorFactory.CreateExecutor(scope, client, operation);
|
||||
await headquartersService.SetOperationStartedAsync(operation.Id);
|
||||
|
||||
state.InvokeOnOperationStarted(operation);
|
||||
|
||||
messageGuid = await executor.ExecuteAsync(stoppingToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await headquartersService.SetOperationEndedWithFailAsync(operation.Id, e.CombineMessages());
|
||||
|
||||
state.InvokeOnOperationEnded(operation);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(messageGuid))
|
||||
{
|
||||
await headquartersService.SetOperationMessageGuidAsync(operation.Id, messageGuid);
|
||||
|
||||
state.InvokeOnOperationExecuted(operation);
|
||||
}
|
||||
|
||||
state.UnsetProcessingOperation(operation);
|
||||
|
||||
@ -10,6 +10,10 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
|
||||
public bool Ready { get; set; }
|
||||
|
||||
public event Action<Operation> OnOperationStarted;
|
||||
public event Action<Operation> OnOperationExecuted;
|
||||
public event Action<Operation> OnOperationEnded;
|
||||
|
||||
public void EnqueueOperation(Operation operation)
|
||||
{
|
||||
operationsInQueue.Enqueue(operation);
|
||||
@ -34,5 +38,32 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
return operationsInQueue.Any(x => x.CampaignId == campaignId) || operationsInProcess.Any(x => x.CampaignId == campaignId);
|
||||
}
|
||||
|
||||
public void InvokeOnOperationStarted(Operation operation)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnOperationStarted?.Invoke(operation);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public void InvokeOnOperationExecuted(Operation operation)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnOperationExecuted?.Invoke(operation);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public void InvokeOnOperationEnded(Operation operation)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnOperationEnded?.Invoke(operation);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,6 +84,8 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
await headquartersService.SetOperationEndedWithFailAsync(entry.operation.Id, e.CombineMessages());
|
||||
|
||||
entry.state.done = true;
|
||||
|
||||
state.InvokeOnOperationEnded(entry.operation);
|
||||
}
|
||||
|
||||
entry.state.attempt++;
|
||||
@ -93,6 +95,7 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
if (entry.state.done)
|
||||
{
|
||||
state.UnsetProcessingOperation(entry.operation);
|
||||
state.InvokeOnOperationEnded(entry.operation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
|
||||
public bool Ready { get; set; }
|
||||
|
||||
public event Action<Operation> OnOperationEnded;
|
||||
|
||||
public void EnqueueOperation(Operation operation)
|
||||
{
|
||||
operationsInQueue.Enqueue(operation);
|
||||
@ -34,5 +36,14 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
return operationsInQueue.Any(x => x.CampaignId == campaignId) || operationsInProcess.Any(x => x.CampaignId == campaignId);
|
||||
}
|
||||
|
||||
public void InvokeOnOperationEnded(Operation operation)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnOperationEnded?.Invoke(operation);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user