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
This commit is contained in:
Developer 02
2025-11-04 14:49:56 +01:00
parent 4997f7d75c
commit 08ca116628
3 changed files with 29 additions and 7 deletions

View File

@@ -1,9 +1,10 @@
using EnvelopeGenerator.Finalizer.Models;
using Microsoft.Extensions.Options;
using Quartz;
namespace EnvelopeGenerator.Finalizer
{
public class Worker : BackgroundService
public class Worker : IJob
{
private readonly ILogger<Worker> _logger;
@@ -15,16 +16,16 @@ namespace EnvelopeGenerator.Finalizer
_options = workerOptions.Value;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
public async Task Execute(IJobExecutionContext context)
{
while (!stoppingToken.IsCancellationRequested)
while (!context.CancellationToken.IsCancellationRequested)
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
}
await Task.Delay(_options.IntervalInMillisecond, stoppingToken);
await Task.Delay(_options.IntervalInMillisecond, context.CancellationToken);
}
}
}
}
}