12345678910111213141516171819202122232425262728293031 |
- namespace BankOperationsUpdate.WorkerService;
- public class Worker : BackgroundService
- {
- private readonly ILogger<Worker> _logger;
- private TimeSpan refreshInterval = TimeSpan.FromMinutes(2);
- private readonly UpdateOperations _updateOperations;
- public Worker(ILogger<Worker> logger, UpdateOperations updateOperations)
- {
- _logger = logger;
- _updateOperations = updateOperations;
- }
- protected override async Task ExecuteAsync(CancellationToken stoppingToken)
- {
- while (!stoppingToken.IsCancellationRequested) {
- try {
- _updateOperations.Execute();
- }
- catch (Exception ex) {
- _logger.LogError(ex.Message);
-
- }
-
- _logger.LogInformation("end of period");
- await Task.Delay(refreshInterval, stoppingToken);
- }
- }
- }
|