/// <summary> /// Runs the health checks. /// </summary> /// <returns>A health response.</returns> public HealthResponse Run() { var healthCheckResults = HealthChecks.Select(TryCheck); var healthResponse = this.CreateHealthResponse(healthCheckResults.SelectMany(x => x)); return(TryCustomizeResponse(healthResponse)); }
/// <summary> /// Runs the health checks asynchronously. /// </summary> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns> /// A task healh response representing the asynchronous operation. /// </returns> public async Task <HealthResponse> RunAsync(CancellationToken cancellationToken = default(CancellationToken)) { var healthCheckResultTasks = HealthChecks.Select(TryCheckAsync); var healthCheckResults = await Task.WhenAll(healthCheckResultTasks).ConfigureAwait(false); var healthResponse = this.CreateHealthResponse(healthCheckResults.SelectMany(x => x)); return(TryCustomizeResponse(healthResponse)); }
/// <summary> /// Runs the health checks asynchronously. /// </summary> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns> /// A task healh response representing the asynchronous operation. /// </returns> public async Task <HealthResponse> RunAsync(CancellationToken cancellationToken = default(CancellationToken)) { var healthCheckResultTasks = HealthChecks.Select(TryCheckAsync); var healthCheckResults = await Task.WhenAll(healthCheckResultTasks).ConfigureAwait(false); var healthResponse = this.CreateHealthResponse(healthCheckResults.SelectMany(x => x)); return(TryCustomizeResponse(healthResponse)); async Task <IReadOnlyList <HealthCheckResult> > TryCheckAsync(IHealthCheck healthCheck) { try { return(await healthCheck.CheckAsync(cancellationToken).ConfigureAwait(false)); } catch (OperationCanceledException) { throw; } catch (Exception ex) { return(GetExceptionHealthCheckResult(healthCheck, ex)); } } }