public async Task <IEnumerable <ServiceCheckResultDto> > Get() { var serviceCheckTasks = _serviceStore.GetAll() .Select(s => _serviceChecker.CheckServiceAsync(s)); var serviceChecks = await Task.WhenAll(serviceCheckTasks); return(serviceChecks); }
private async Task CheckServices(IEnumerable <Shared.Service> services, List <ServiceCheckResultDto> aggregateErros) { foreach (var service in services) { var checkResult = await _serviceChecker.CheckServiceAsync(service); if (checkResult.Errors.Count != 0) { aggregateErros.Add(checkResult); } } }
public async Task Execute(IJobExecutionContext context) { var failed = new List <ServiceEntry>(); var checkTasks = _settings.Services.Select(x => _checker.CheckServiceAsync(x, System.Threading.CancellationToken.None)); Task <CheckResult[]> allTask = null; try { _logger.LogTrace("Checking service status for all services"); allTask = Task.WhenAll(checkTasks); var results = await allTask; foreach (var result in results) { if (result.IsSuccess) { _logger.LogInformation("OK - {Name}", result.Service.Name); } else { _logger.LogWarning("FAILED - {@Result}", result); } string status = result.IsSuccess ? "SUCCESS" : "FAIL"; _repository.SetServiceStatus(result.Service, status); } var failedServices = results.Where(x => !x.IsSuccess).Select(y => y.Service); if (failedServices != null && failedServices.Any()) { await _alerter.SendServiceDownAlertAsync(failedServices); } } catch (Exception ex) { _logger.LogError(ex, "An error occurred"); } }