Add operation executor

This commit is contained in:
2025-10-25 20:30:49 +09:00
parent 59470b49d1
commit 891d462af1
19 changed files with 144 additions and 52 deletions

View File

@ -1,6 +1,7 @@
using Hcs.Broker;
using Hcs.Broker.Logger;
using Hcs.Broker.MessageCapturer;
using Hcs.WebApp.BackgroundServices.Executors;
using Hcs.WebApp.Config;
using Hcs.WebApp.Services;
@ -12,6 +13,7 @@ namespace Hcs.WebApp.BackgroundServices
private readonly OperationExecutionState state = state;
private readonly IServiceScopeFactory scopeFactory = scopeFactory;
private readonly ExecutorFactory executorFactory = new();
private Broker.Logger.ILogger logger;
private IMessageCapturer messageCapturer;
@ -19,7 +21,7 @@ namespace Hcs.WebApp.BackgroundServices
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await InitializeState();
await InitializeStateAsync();
InitializeClient();
@ -30,19 +32,33 @@ namespace Hcs.WebApp.BackgroundServices
{
while (state.TryDequeueOperation(out var operation))
{
await operationService.SetOperationMessageGuid(operation.Id, Guid.NewGuid().ToString());
var messageGuid = string.Empty;
try
{
var executor = executorFactory.CreateExecutor(client, operation);
messageGuid = await executor.ExecuteAsync(stoppingToken);
}
catch
{
state.EnqueueOperation(operation);
}
if (!string.IsNullOrEmpty(messageGuid))
{
await operationService.SetOperationMessageGuidAsync(operation.Id, messageGuid);
}
}
await Task.Delay(SLEEP_TIME, stoppingToken);
}
}
private async Task InitializeState()
private async Task InitializeStateAsync()
{
using var scope = scopeFactory.CreateScope();
var operationService = scope.ServiceProvider.GetRequiredService<OperationService>();
var operations = await operationService.GetInitiatedOperations();
var operations = await operationService.GetInitiatedOperationsAsync();
foreach (var operation in operations)
{
state.EnqueueOperation(operation);