31 lines
920 B
C#
31 lines
920 B
C#
using EnvelopeGenerator.Finalizer.Models;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace EnvelopeGenerator.Finalizer
|
|
{
|
|
public class Worker : BackgroundService
|
|
{
|
|
private readonly ILogger<Worker> _logger;
|
|
|
|
private readonly WorkerOptions _options;
|
|
|
|
public Worker(ILogger<Worker> logger, IOptions<WorkerOptions> workerOptions)
|
|
{
|
|
_logger = logger;
|
|
_options = workerOptions.Value;
|
|
}
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
if (_logger.IsEnabled(LogLevel.Information))
|
|
{
|
|
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
|
}
|
|
await Task.Delay(_options.IntervalInMillisecond, stoppingToken);
|
|
}
|
|
}
|
|
}
|
|
}
|