Files
parr_api/PARR.Worker/PARR.Worker/Worker.cs

49 lines
1.8 KiB
C#

using PARR.AIHIT;
using PARR.Worker.Settings;
namespace PARR.Worker
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> logger;
private readonly IServiceProvider serviceProvider;
private readonly WorkerSettings workerSettings;
public Worker(ILogger<Worker> logger,
IServiceProvider serviceProvider,
WorkerSettings workerSettings
)
{
this.logger = logger;
this.serviceProvider = serviceProvider;
this.workerSettings = workerSettings;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
logger.LogInformation("--- Сервис запущен! ---");
while (!stoppingToken.IsCancellationRequested)
{
logger.LogInformation("--- --- --- --- Начало синхронизации --- --- --- ---");
using var scope = serviceProvider.CreateScope();
var services = scope.ServiceProvider;
var syncer = services.GetService<ISyncher>();
if (syncer != null) await syncer.InvokeFromDatabase();
//var hosts = await hostService.Get().ToListAsync();
//foreach ( var host in hosts ) { logger.LogInformation($"{host.HostName}"); }
//await attachmentUploader.UploadAsync();
//logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
logger.LogInformation("=== === === === Конец синхронизации === === === ===");
var mills = (int?) workerSettings?.OccursEvery.TotalMilliseconds ?? 60*1000;
await Task.Delay(mills, stoppingToken);
}
}
}
}