Get hcs request result separately
This commit is contained in:
@ -60,7 +60,7 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
|
||||
var operations = await headquartersService.GetInitiatedOperationsAsync();
|
||||
var operations = await headquartersService.GetNotExecutedOperationsAsync();
|
||||
foreach (var operation in operations)
|
||||
{
|
||||
state.EnqueueOperation(operation);
|
||||
@ -70,7 +70,7 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
private void InitializeClient()
|
||||
{
|
||||
logger = new ActionLogger();
|
||||
messageCapturer = new FileMessageCapturer("messages", logger);
|
||||
messageCapturer = new FileMessageCapturer("outgoing", logger);
|
||||
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
var configuration = scope.ServiceProvider.GetRequiredService<IConfiguration>();
|
||||
|
||||
@ -1,7 +1,61 @@
|
||||
namespace Hcs.WebApp.BackgroundServices
|
||||
using Hcs.Broker;
|
||||
using Hcs.Broker.Logger;
|
||||
using Hcs.Broker.MessageCapturer;
|
||||
using Hcs.WebApp.Config;
|
||||
using Hcs.WebApp.Services;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public class ResultWaitService
|
||||
public class ResultWaitService(ResultWaitState state, IServiceScopeFactory scopeFactory) : BackgroundService
|
||||
{
|
||||
// TODO
|
||||
private const int SLEEP_TIME = 30000;
|
||||
|
||||
private readonly ResultWaitState state = state;
|
||||
private readonly IServiceScopeFactory scopeFactory = scopeFactory;
|
||||
|
||||
private Broker.Logger.ILogger logger;
|
||||
private IMessageCapturer messageCapturer;
|
||||
private IClient client;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
await InitializeStateAsync();
|
||||
|
||||
InitializeClient();
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
while (state.TryDequeueOperation(out var operation))
|
||||
{
|
||||
if (stoppingToken.IsCancellationRequested) return;
|
||||
}
|
||||
|
||||
await Task.Delay(SLEEP_TIME, stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InitializeStateAsync()
|
||||
{
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
|
||||
var operations = await headquartersService.GetResultWaitingOperationsAsync();
|
||||
foreach (var operation in operations)
|
||||
{
|
||||
state.EnqueueOperation(operation);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeClient()
|
||||
{
|
||||
logger = new ActionLogger();
|
||||
messageCapturer = new FileMessageCapturer("incoming", logger);
|
||||
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
var configuration = scope.ServiceProvider.GetRequiredService<IConfiguration>();
|
||||
var config = configuration.GetSection("BrokerConfig").Get<BrokerConfig>()!;
|
||||
var clientProvider = scope.ServiceProvider.GetRequiredService<IClientProvider>();
|
||||
client = clientProvider.CreateClient(config, logger, messageCapturer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
namespace Hcs.WebApp.BackgroundServices.ResultWaiters
|
||||
{
|
||||
public interface IResultWaiter
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user