Exemple #1
0
        public async Task <IEnumerable <LivenessResult> > IsHealthy(string path, HttpContext httpContext, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"BeatPulse is checking health on [BeatPulsePath]/{path}");

            if (String.IsNullOrEmpty(path))
            {
                var livenessResults = new List <LivenessResult>();

                foreach (var liveness in _beatPulseContext.AllLiveness)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        _logger.LogWarning($"BeatPulse execution is cancelled");

                        break;
                    }

                    var healthCheckResult = await RunLiveness(liveness, httpContext, cancellationToken);

                    livenessResults.Add(healthCheckResult);

                    if (!healthCheckResult.IsHealthy)
                    {
                        //break when first check is not healthy

                        var warningMessage = cancellationToken.IsCancellationRequested
                            ? $"Liveness {liveness.Name} was cancelled on timeout"
                            : $"Liveness {liveness.Name} is not healthy";

                        _logger.LogWarning(warningMessage);

                        return(livenessResults);
                    }
                }

                return(livenessResults);
            }
            else
            {
                var liveness = _beatPulseContext.FindLiveness(path);

                if (liveness != null)
                {
                    var livenessResult = await RunLiveness(liveness, httpContext, cancellationToken);

                    return(new[] { livenessResult });
                }
            }

            return(Enumerable.Empty <LivenessResult>());
        }
        public async Task <IEnumerable <LivenessResult> > IsHealthy(string path, BeatPulseOptions options, HttpContext httpContext)
        {
            _logger.LogInformation($"BeatPulse is checking health on [BeatPulsePath]/{path}");

            if (String.IsNullOrEmpty(path))
            {
                var livenessResults = new List <LivenessResult>();

                foreach (var liveness in _beatPulseContext.AllLiveness)
                {
                    var healthCheckResult = await RunLiveness(liveness, options, httpContext);

                    await RunTrackers(healthCheckResult);

                    livenessResults.Add(healthCheckResult);

                    if (!healthCheckResult.IsHealthy && !options.DetailedOutput)
                    {
                        //if is unhealthy and not detailed options is true return inmediatly

                        _logger.LogWarning($"Liveness {liveness.Name} is not healthy");

                        return(livenessResults);
                    }
                }

                return(livenessResults);
            }
            else
            {
                var liveness = _beatPulseContext.FindLiveness(path);

                if (liveness != null)
                {
                    var livenessResult = await RunLiveness(liveness, options, httpContext);

                    return(new[] { livenessResult });
                }
            }

            return(Enumerable.Empty <LivenessResult>());
        }