- Removed inheritance from BackgroundService - Implemented Quartz IJob interface for better scheduling control - Replaced ExecuteAsync with Execute(IJobExecutionContext) - Updated cancellation handling to use context.CancellationToken
31 lines
924 B
C#
31 lines
924 B
C#
using EnvelopeGenerator.Finalizer.Models;
|
|
using Microsoft.Extensions.Options;
|
|
using Quartz;
|
|
|
|
namespace EnvelopeGenerator.Finalizer
|
|
{
|
|
public class Worker : IJob
|
|
{
|
|
private readonly ILogger<Worker> _logger;
|
|
|
|
private readonly WorkerOptions _options;
|
|
|
|
public Worker(ILogger<Worker> logger, IOptions<WorkerOptions> workerOptions)
|
|
{
|
|
_logger = logger;
|
|
_options = workerOptions.Value;
|
|
}
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
while (!context.CancellationToken.IsCancellationRequested)
|
|
{
|
|
if (_logger.IsEnabled(LogLevel.Information))
|
|
{
|
|
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
|
}
|
|
await Task.Delay(_options.IntervalInMillisecond, context.CancellationToken);
|
|
}
|
|
}
|
|
}
|
|
} |