Пример #1
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Pinging Courses API");

            var timer    = Stopwatch.StartNew();
            var response = await _apiClient.GetResponseCode(new GetPingRequest());

            timer.Stop();

            if ((int)response == 200)
            {
                var durationString = timer.Elapsed.ToHumanReadableString();

                _logger.LogInformation($"Courses API ping successful and took {durationString}");

                return(HealthCheckResult.Healthy(HealthCheckResultDescription,
                                                 new Dictionary <string, object> {
                    { "Duration", durationString }
                }));
            }

            _logger.LogWarning($"Courses API ping failed : [Code: {response}]");
            return(HealthCheckResult.Unhealthy(HealthCheckResultDescription));
        }