Fulfill export executor
This commit is contained in:
@ -7,13 +7,13 @@ using Hcs.WebApp.Services;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public class OperationExecutionService(OperationExecutionState state, IServiceScopeFactory scopeFactory) : BackgroundService
|
||||
public class OperationExecutionService(OperationExecutionState state, ExecutorFactory executorFactory, IServiceScopeFactory scopeFactory) : BackgroundService
|
||||
{
|
||||
private const int SLEEP_TIME = 30000;
|
||||
|
||||
private readonly OperationExecutionState state = state;
|
||||
private readonly ExecutorFactory executorFactory = executorFactory;
|
||||
private readonly IServiceScopeFactory scopeFactory = scopeFactory;
|
||||
private readonly ExecutorFactory executorFactory = new();
|
||||
|
||||
private Broker.Logger.ILogger logger;
|
||||
private IMessageCapturer messageCapturer;
|
||||
|
||||
@ -3,9 +3,10 @@ using Hcs.WebApp.Data.Hcs;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices.OperationExecutors
|
||||
{
|
||||
public abstract class ExecutorBase(IClient client, Operation operation) : IExecutor
|
||||
public abstract class ExecutorBase(IClient client, IServiceScopeFactory scopeFactory, Operation operation) : IExecutor
|
||||
{
|
||||
protected readonly IClient client = client;
|
||||
protected readonly IServiceScopeFactory scopeFactory = scopeFactory;
|
||||
protected readonly Operation operation = operation;
|
||||
|
||||
public abstract Task<string> ExecuteAsync(CancellationToken cancellationToken);
|
||||
|
||||
@ -4,14 +4,16 @@ using Hcs.WebApp.Data.Hcs;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices.OperationExecutors
|
||||
{
|
||||
public class ExecutorFactory
|
||||
public class ExecutorFactory(IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
protected readonly IServiceScopeFactory scopeFactory = scopeFactory;
|
||||
|
||||
public IExecutor CreateExecutor(IClient client, Operation operation)
|
||||
{
|
||||
switch (operation.Type)
|
||||
{
|
||||
case Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1:
|
||||
return new ExportNsiItemExecutor_15_7_0_1(client, operation);
|
||||
return new ExportNsiItemExecutor_15_7_0_1(client, scopeFactory, operation);
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
using Hcs.Broker;
|
||||
using Hcs.Service.Async.NsiCommon;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
using Hcs.WebApp.Services;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices.OperationExecutors.NsiCommon
|
||||
{
|
||||
public class ExportNsiItemExecutor_15_7_0_1(IClient client, Operation operation) : ExecutorBase(client, operation)
|
||||
public class ExportNsiItemExecutor_15_7_0_1(IClient client, IServiceScopeFactory scopeFactory, Operation operation) : ExecutorBase(client, scopeFactory, operation)
|
||||
{
|
||||
public override async Task<string> ExecuteAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await client.NsiCommon.RequestExportNsiItemAsync(1, Service.Async.NsiCommon.ListGroup.NSI, cancellationToken);
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
var registryService = scope.ServiceProvider.GetRequiredService<RegistryService>();
|
||||
var registry = await registryService.GetRegistryByOperationId(operation.Id);
|
||||
return await client.NsiCommon.RequestExportNsiItemAsync(registry.Number, ListGroup.NSI, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Hcs.WebApp.BackgroundServices;
|
||||
using Hcs.WebApp.BackgroundServices.CampaignManagers;
|
||||
using Hcs.WebApp.BackgroundServices.OperationExecutors;
|
||||
using Hcs.WebApp.Components;
|
||||
using Hcs.WebApp.Components.Shared;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
@ -65,6 +66,7 @@ builder.Services.AddScoped<RegistryService>();
|
||||
builder.Services.AddSingleton<CampaignManagementState>();
|
||||
builder.Services.AddSingleton<OperationExecutionState>();
|
||||
builder.Services.AddSingleton<ManagerFactory>();
|
||||
builder.Services.AddSingleton<ExecutorFactory>();
|
||||
|
||||
builder.Services.AddHostedService<CampaignManagementService>();
|
||||
builder.Services.AddHostedService<OperationExecutionService>();
|
||||
|
||||
@ -14,5 +14,11 @@ namespace Hcs.WebApp.Services
|
||||
where registry.IsCommon == isCommon
|
||||
select registry).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Registry> GetRegistryByOperationId(int operationId)
|
||||
{
|
||||
using var context = factory.CreateDbContext();
|
||||
return await context.Registries.SingleAsync(x => x.LastSyncOperationId == operationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user