src/Library/NetPro.Checker/HealthCheckRegistry.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

namespace NetPro.Checker
{
    /// <summary>
    /// Registry for health checks
    /// </summary>
    public class HealthCheckRegistry
    {
        public struct HealthStatus
        {
            /// <summary>
            /// Flag indicating whether any checks are registered
            /// </summary>
            //[JsonIgnore]
            public readonly bool HasRegisteredChecks;

            /// <summary>
            /// Whether or not all health checks have passed
            /// </summary>
            public readonly bool IsHealthy;

            /// <summary>
            /// Array containing result of each registered health check
            /// </summary>
            public readonly HealthCheck.Result[] Results;

            public HealthStatus(IEnumerable<HealthCheck.Result> results)
            {
                Results = results.ToArray();
                IsHealthy = Results.All(r => r.Check.IsHealthy);
                HasRegisteredChecks = Results.Length > 0;
            }
        }

        private static readonly ConcurrentDictionary<string, HealthCheck> Checks = new ConcurrentDictionary<string, HealthCheck>();

        public static void RegisterHealthCheck(string name, Action check)
        {
            RegisterHealthCheck(new HealthCheck(name, check));
        }

        public static void RegisterHealthCheck(string name, Func<string> check)
        {
            RegisterHealthCheck(new HealthCheck(name, check));
        }

        public static void RegisterHealthCheck(string name, Func<HealthResponse> check)
        {
            RegisterHealthCheck(new HealthCheck(name, check));
        }

        public static void RegisterHealthCheck(HealthCheck healthCheck)
        {
            Checks.TryAdd(healthCheck.Name, healthCheck);
        }

后面还有 13 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。