Developer 02 08ca116628 refactor(worker): replace BackgroundService with Quartz IJob for scheduled execution
- Removed inheritance from BackgroundService
- Implemented Quartz IJob interface for better scheduling control
- Replaced ExecuteAsync with Execute(IJobExecutionContext)
- Updated cancellation handling to use context.CancellationToken
2025-11-04 14:49:56 +01:00

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);
}
}
}
}