コード例 #1
0
        private async Task ServiceStatusPingAsync(TimerAwaitable timer)
        {
            using (timer)
            {
                timer.Start();

                while (await timer)
                {
                    try
                    {
                        // Check if last send time is longer than default keep-alive ticks and then send ping
                        if (Stopwatch.GetTimestamp() - Interlocked.Read(ref _lastSendTimestamp) > DefaultGetServiceStatusTicks)
                        {
                            await WriteAsync(RuntimeServicePingMessage.GetStatusPingMessage(true));

                            Interlocked.Exchange(ref _lastSendTimestamp, Stopwatch.GetTimestamp());
                            Log.SentServiceStatusPing(Logger);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.FailedSendingServiceStatusPing(Logger, e);
                    }
                }
            }
        }
コード例 #2
0
            private TimerAwaitable Init()
            {
                Log.StartingPingTimer(_logger, _pingName, _intervalTime);

                _lastSendTimestamp = Stopwatch.GetTimestamp();
                var timer = new TimerAwaitable(_dueTime, _intervalTime);

                return(timer);
            }
コード例 #3
0
 public bool Start()
 {
     if (Interlocked.Increment(ref _counter) == 1)
     {
         _timer = Init();
         _timer.Start();
         _ = PingAsync(_timer);
         return(true);
     }
     return(false);
 }
コード例 #4
0
            public CustomizedPingTimer(ILogger logger, string pingName, Func <Task> writePing, TimeSpan dueTime, TimeSpan intervalTime)
            {
                _logger           = logger;
                _pingName         = pingName;
                _writePing        = writePing;
                _dueTime          = dueTime;
                _intervalTime     = intervalTime;
                _defaultPingTicks = intervalTime.Seconds * Stopwatch.Frequency;

                _timer = Init();
            }
コード例 #5
0
        private TimerAwaitable StartServiceStatusPingTimer()
        {
            Log.StartingServiceStatusPingTimer(Logger, DefaultGetServiceStatusInterval);

            _lastSendTimestamp = Stopwatch.GetTimestamp();
            var timer = new TimerAwaitable(DefaultGetServiceStatusInterval, DefaultGetServiceStatusInterval);

            _ = ServiceStatusPingAsync(timer);

            return(timer);
        }
コード例 #6
0
        public RestHealthCheckService(RestClientFactory clientFactory, IServiceEndpointManager serviceEndpointManager, ILogger <RestHealthCheckService> logger, string hubName, IOptions <HealthCheckOption> options)
        {
            var checkOptions = options.Value;

            _enable = serviceEndpointManager.Endpoints.Count > 1 || checkOptions.EnabledForSingleEndpoint;
            if (_enable)
            {
                _clientFactory          = clientFactory;
                _serviceEndpointManager = serviceEndpointManager;
                _logger  = logger;
                _hubName = hubName;

                _checkInterval = checkOptions.CheckInterval.GetValueOrDefault(_checkInterval);
                _retryInterval = checkOptions.RetryInterval.GetValueOrDefault(_retryInterval);
                _timer         = new TimerAwaitable(_checkInterval, _checkInterval);
            }
        }
コード例 #7
0
            private async Task PingAsync(TimerAwaitable timer)
            {
                while (await timer)
                {
                    try
                    {
                        // Check if last send time is longer than default keep-alive ticks and then send ping
                        if (Stopwatch.GetTimestamp() - Interlocked.Read(ref _lastSendTimestamp) > _defaultPingTicks)
                        {
                            await _writePing.Invoke();

                            Interlocked.Exchange(ref _lastSendTimestamp, Stopwatch.GetTimestamp());
                            Log.SentPing(_logger, _pingName);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.FailedSendingPing(_logger, _pingName, e);
                    }
                }
            }
コード例 #8
0
 public ObjectWithTimerAwaitable(TaskCompletionSource tcs)
 {
     _tcs   = tcs;
     _timer = new TimerAwaitable(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1));
     _timer.Start();
 }
コード例 #9
0
 public WeakServiceConnectionContainer(IServiceConnectionFactory serviceConnectionFactory,
                                       int fixedConnectionCount, HubServiceEndpoint endpoint, ILogger logger)
     : base(serviceConnectionFactory, fixedConnectionCount, endpoint, logger: logger)
 {
     _timer = StartServiceStatusPingTimer();
 }