private static async Task ProcessResultPlugins( IAutoHealthCheckContext context, HealthyResponse healthyResponse) { foreach (var resultPlugin in context.Configurations.ResultPlugins) { try { await resultPlugin.ActionAfterResult(healthyResponse).ConfigureAwait(false); switch (healthyResponse.Success) { case true: await resultPlugin.ActionAfterSuccess(healthyResponse).ConfigureAwait(false); break; case false: await resultPlugin.ActionAfterFail(healthyResponse).ConfigureAwait(false); break; } } catch (Exception) { // prevent failing when plugin is called. // todo : add log } } }
public static async Task <HealthyResponse> ProcessResult( IAutoHealthCheckContext context, Stopwatch watcher, HttpResponseMessage[] endpointResults, ProbeResult[] probeResults) { var healthyResponse = new HealthyResponse { ElapsedSecondsTest = watcher.ElapsedMilliseconds / 1000, Success = true // default }; // check if there is something to evaluate result. if (endpointResults.Length != 0 || probeResults.Length != 0) { foreach (var result in endpointResults) { if (context.Configurations.PassCheckRule.Invoke(result)) { continue; } healthyResponse.Success = false; healthyResponse.UnhealthyEndpoints.Add(new UnhealthyEndpoint { HttpStatusCode = (int)result.StatusCode, Route = result.RequestMessage?.RequestUri.ToString(), HttpVerb = result.RequestMessage?.Method.Method }); } foreach (var probe in probeResults) { if (probe.Succeed) { continue; } healthyResponse.Success = false; healthyResponse.UnhealthyProbes.Add(new UnhealthyProbe { Name = probe.Name, ErrorMessage = probe.ErrorMessage, CustomData = probe.CustomData }); } } // get status code healthyResponse.HttpStatus = healthyResponse.Success ? context.Configurations.DefaultHealthyResponseCode : context.Configurations.DefaultUnHealthyResponseCode; await ProcessResultPlugins(context, healthyResponse).ConfigureAwait(false); return(healthyResponse); }