protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await Task.Delay(MinutesToMiliSeconds(_configuration.InitialDelayInMinutes)); var services = _serviceStore.GetAll(); var previousCheckNotFoundErrors = true; _logger.LogInformation($"Start periodic service checking with {_configuration.PeriodicityInMinutes} minute periodicity."); while (!stoppingToken.IsCancellationRequested) { var aggregateErros = new List <ServiceCheckResultDto>(); _logger.LogInformation("Checking services..."); await CheckServices(services, aggregateErros); _logger.LogInformation("Checking services finished"); if (aggregateErros.Count != 0 && previousCheckNotFoundErrors) { _logger.LogInformation("Sending notification about unhealthy services..."); await _notificationService.SendErrorsAsync(aggregateErros); } previousCheckNotFoundErrors = aggregateErros.Count == 0; await Task.Delay(MinutesToMiliSeconds(_configuration.PeriodicityInMinutes), stoppingToken); } _logger.LogInformation("Stop periodic service checking."); }
public async Task <IEnumerable <ServiceCheckResultDto> > Get() { var serviceCheckTasks = _serviceStore.GetAll() .Select(s => _serviceChecker.CheckServiceAsync(s)); var serviceChecks = await Task.WhenAll(serviceCheckTasks); return(serviceChecks); }