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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user