Initialize broker client in background service

This commit is contained in:
2025-10-24 17:39:10 +09:00
parent e8fab0c3dd
commit 59470b49d1
2 changed files with 24 additions and 2 deletions

View File

@ -1,4 +1,8 @@
using Hcs.WebApp.Services; using Hcs.Broker;
using Hcs.Broker.Logger;
using Hcs.Broker.MessageCapturer;
using Hcs.WebApp.Config;
using Hcs.WebApp.Services;
namespace Hcs.WebApp.BackgroundServices namespace Hcs.WebApp.BackgroundServices
{ {
@ -9,10 +13,16 @@ namespace Hcs.WebApp.BackgroundServices
private readonly OperationExecutionState state = state; private readonly OperationExecutionState state = state;
private readonly IServiceScopeFactory scopeFactory = scopeFactory; private readonly IServiceScopeFactory scopeFactory = scopeFactory;
private Broker.Logger.ILogger logger;
private IMessageCapturer messageCapturer;
private IClient client;
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{ {
await InitializeState(); await InitializeState();
InitializeClient();
var scope = scopeFactory.CreateScope(); var scope = scopeFactory.CreateScope();
var operationService = scope.ServiceProvider.GetRequiredService<OperationService>(); var operationService = scope.ServiceProvider.GetRequiredService<OperationService>();
@ -38,5 +48,17 @@ namespace Hcs.WebApp.BackgroundServices
state.EnqueueOperation(operation); state.EnqueueOperation(operation);
} }
} }
private void InitializeClient()
{
logger = new ActionLogger();
messageCapturer = new FileMessageCapturer("messages", 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);
}
} }
} }

View File

@ -156,7 +156,7 @@
break; break;
case CommonPageState.OperationWaiting: case CommonPageState.OperationWaiting:
syncText = "Синхронизация в процессе"; syncText = "Идет синхронизация...";
break; break;
} }
} }