35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using Hcs.WebApp.BackgroundServices.DataParsers;
|
|
using Hcs.WebApp.Services;
|
|
|
|
namespace Hcs.WebApp.BackgroundServices
|
|
{
|
|
public class DataParsingService(
|
|
DataParsingState state,
|
|
DataParserFactory dataParserFactory,
|
|
IServiceScopeFactory scopeFactory) : BackgroundService
|
|
{
|
|
private readonly DataParsingState state = state;
|
|
private readonly DataParserFactory dataParserFactory = dataParserFactory;
|
|
private readonly IServiceScopeFactory scopeFactory = scopeFactory;
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
await InitializeStateAsync();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
state.Ready = true;
|
|
}
|
|
}
|
|
}
|