コード例 #1
0
 private void HandleNewEndpoint(MonitorableEndpoint endpoint)
 {
     if (_tasks.TryAdd(endpoint, CreateTaskFor(endpoint)))
     {
         _onNewTask.Set();
     }
 }
コード例 #2
0
        private async Task MonitorEndpointAsync(MonitorableEndpoint endpoint, CancellationToken cancellationToken)
        {
            int errorCounter = 0;

            await _timeCoordinator.Delay(GetRandomizedDelay(), cancellationToken);
            while (!cancellationToken.IsCancellationRequested && !endpoint.IsDisposed)
            {
                try
                {
                    var delay = _timeCoordinator.Delay(_settings.HealthCheckInterval, cancellationToken);
                    await Task.WhenAll(endpoint.CheckHealth(_sampler, cancellationToken), delay);
                    errorCounter = 0;
                }
                catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
                {
                }
                catch (AggregateException e) when (cancellationToken.IsCancellationRequested && e.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
                {
                }
                catch (Exception e)
                {
                    errorCounter = Math.Min(errorCounter + 1, MaxErrorDelayInSeconds);
                    Logger.ErrorFormat("Monitoring error ({0} occurrence): {1}", errorCounter, e.ToString());
                    await _timeCoordinator.Delay(TimeSpan.FromSeconds(errorCounter), cancellationToken);
                }
            }
        }
コード例 #3
0
        private async Task MonitorEndpointAsync(MonitorableEndpoint endpoint, CancellationToken cancellationToken)
        {
            int errorCounter = 0;

            await _timeCoordinator.Delay(GetRandomizedDelay(), cancellationToken);

            while (!cancellationToken.IsCancellationRequested && !endpoint.IsDisposed)
            {
                try
                {
                    var delay = _timeCoordinator.Delay(_settings.HealthCheckInterval, cancellationToken);
                    await Task.WhenAll(endpoint.CheckHealth(_sampler, cancellationToken), delay);

                    errorCounter = 0;
                }
                catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested)
                {
                }
                catch (AggregateException e) when(cancellationToken.IsCancellationRequested && e.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
                {
                }
                catch (Exception e)
                {
                    errorCounter = Math.Min(errorCounter + 1, MaxErrorDelayInSeconds);
                    Logger.ErrorFormat("Monitoring error ({0} occurrence): {1}", errorCounter, e.ToString());
                    await _timeCoordinator.Delay(TimeSpan.FromSeconds(errorCounter), cancellationToken);
                }
            }
        }
コード例 #4
0
        private async Task <MonitorableEndpoint> CreateTaskFor(MonitorableEndpoint endpoint)
        {
            await _timeCoordinator.Delay(GetRandomizedDelay(), _cancellation.Token);

            while (!_cancellation.IsCancellationRequested && !endpoint.IsDisposed)
            {
                var delay = _timeCoordinator.Delay(_settings.HealthCheckInterval, _cancellation.Token);
                await Task.WhenAll(endpoint.CheckHealth(_sampler, _cancellation.Token), delay);
            }
            return(endpoint);
        }
コード例 #5
0
 private void HandleNewEndpoint(MonitorableEndpoint endpoint)
 {
     _executor.TryRegisterTaskFor(endpoint, MonitorEndpointAsync);
 }
コード例 #6
0
 private void HandleNewEndpoint(MonitorableEndpoint endpoint)
 {
     _executor.TryRegisterTaskFor(endpoint, MonitorEndpointAsync);
 }