예제 #1
0
        public void Stop(Exception exception, IKillSwitchState previousState)
        {
            var stopped = new StoppedKillSwitchState(this, exception);

            Interlocked.CompareExchange(ref _state, stopped, previousState);
            if (_state != stopped)
            {
                return;
            }

            if (previousState is StartedKillSwitchState started)
            {
                started.LogThreshold();
            }

            Task.Run(() => StopReceiveEndpoint(stopped));
        }
예제 #2
0
        async Task StopReceiveEndpoint(StoppedKillSwitchState state)
        {
            try
            {
                await _receiveEndpoint.Stop().ConfigureAwait(false);

                var startTime = DateTime.UtcNow + RestartTimeout;

                LogContext.Info?.Log("Kill Switch stopped endpoint, restarting at {StartTime}: {InputAddress}", startTime, _receiveEndpoint.InputAddress);
            }
            catch (Exception exception)
            {
                LogContext.Error?.Log(exception, "Kill Switch failed to stop endpoint: {InputAddress}", _receiveEndpoint.InputAddress);
            }
            finally
            {
                state.Activate();
            }
        }