private static AgentServiceCheck CreateCheck(ConsulDiscoveryOptions options, HeartbeatOptions heartbeatOptions)
        {
            if (!options.RegisterHealthCheck)
            {
                return(null);
            }

            TimeSpan?deregisterCriticalServiceAfter = null;
            TimeSpan?timeout = null;

            if (!string.IsNullOrWhiteSpace(options.HealthCheckTimeout))
            {
                timeout = DateTimeConversions.ToTimeSpan(options.HealthCheckTimeout);
            }

            if (!string.IsNullOrWhiteSpace(options.HealthCheckCriticalTimeout))
            {
                deregisterCriticalServiceAfter = DateTimeConversions.ToTimeSpan(options.HealthCheckCriticalTimeout);
            }

            var check = new AgentServiceCheck
            {
                Timeout = timeout,
                DeregisterCriticalServiceAfter = deregisterCriticalServiceAfter
            };

            if (heartbeatOptions.Enable)
            {
                return(SetHeartbeat(check, heartbeatOptions) ? check : null);
            }

            return(SetHttpCheck(check, options) ? check : null);
        }
 public ConsulServiceRegistry(ConsulClient client, IOptions <ConsulDiscoveryOptions> consulDiscoveryOptionsAccessor, TtlScheduler ttlScheduler, IOptions <HeartbeatOptions> heartbeatOptionsAccessor, ILogger <ConsulServiceRegistry> logger)
 {
     _client = client;
     _consulDiscoveryOptions = consulDiscoveryOptionsAccessor.Value;
     _ttlScheduler           = ttlScheduler;
     _heartbeatOptions       = heartbeatOptionsAccessor.Value;
     _logger = logger;
 }
        private static bool SetHeartbeat(AgentServiceCheck check, HeartbeatOptions heartbeatOptions)
        {
            if (!heartbeatOptions.Enable || heartbeatOptions.TtlValue <= 0 || string.IsNullOrEmpty(heartbeatOptions.TtlUnit))
            {
                return(false);
            }

            check.Interval = null;
            check.HTTP     = null;

            TimeSpan?ttl = DateTimeConversions.ToTimeSpan(heartbeatOptions.TtlValue + heartbeatOptions.TtlUnit);

            check.TTL = ttl;

            return(true);
        }
        private static AgentServiceRegistration BuildRegistration(
            ConsulDiscoveryOptions options,
            HeartbeatOptions heartbeatOptions)
        {
            if (!options.Port.HasValue)
            {
                throw new ArgumentException("Port can not be empty.");
            }

            return(new AgentServiceRegistration
            {
                Address = options.HostName,
                ID = options.InstanceId,
                Name = options.ServiceName,
                Port = options.Port.Value,
                Tags = options.Tags,
                Check = CreateCheck(options, heartbeatOptions)
            });
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HeartbeatOptions"/> class.
 /// </summary>
 private HeartbeatOptions(HeartbeatOptions other)
 {
     PeriodMilliseconds  = other.PeriodMilliseconds;
     TimeoutMilliseconds = other.TimeoutMilliseconds;
 }
Esempio n. 6
0
 public OverviewPage(HeartbeatOptions options)
 {
     _options = options ?? throw new ArgumentNullException(nameof(options));
 }