Esempio n. 1
0
        private Task Notify(ICircuitRequest request, ICircuitResponse response, TimeSpan executionTime)
        {
            if (_listeners == null || !_listeners.Any())
            {
                return(Task.CompletedTask);
            }

            try
            {
                var data = new CircuitStatusData
                {
                    RequestId     = request.RequestId,
                    CircuitKey    = request.CircuitKey,
                    Context       = request.Context,
                    ExecutionTime = executionTime,
                    Status        = response.Status
                };

                var tasks = _listeners.Select(x => x.Notify(data)).ToArray();

                return(Task.WhenAll(tasks));
            }
            catch (Exception e)
            {
                CircuitBreakerLog.LogError(e, e.Message);
            }

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        private static void WriteStatus(ICircuitResponse response)
        {
            Console.ForegroundColor = response.Status == CircuitStatus.Succeed
                ? ConsoleColor.Green
                : response.Status == CircuitStatus.Timeout
                    ? ConsoleColor.Yellow
                    : response.Status == CircuitStatus.Failed
                        ? ConsoleColor.Red
                        : ConsoleColor.Magenta;

            Console.WriteLine(response.Status);
            Console.ForegroundColor = ConsoleColor.White;
        }