internal static CircuitBreakerState FromState(CircuitBreakerFunctionState functionState) { CircuitBreakerState result = null; if (functionState != null) { if (functionState.State == Closed.ToString()) { result = Closed; } if (functionState.State == Open.ToString()) { result = Open; } if (functionState.State == HalfOpen.ToString()) { result = HalfOpen; } result.Timestamp = functionState.Timestamp; } return(result); }
public override Task OnExecutingAsync(FunctionExecutingContext executingContext, CancellationToken cancellationToken) { var request = executingContext.Arguments.Values.FirstOrDefault(argument => argument is HttpRequest) as HttpRequest; var stateReaderService = request.HttpContext.RequestServices.GetRequiredService <ICircuitBreakerStateService>(); _state = stateReaderService.GetStateAsync(_serviceName, executingContext.FunctionName).Result; if (_state != null && _state.IsOpen) { request.HttpContext.Response.StatusCode = 403; request.HttpContext.Response.Body.Flush(); request.HttpContext.Response.Body.Close(); throw new OpenCircuitException(_serviceName, executingContext.FunctionName); } return(base.OnExecutingAsync(executingContext, cancellationToken)); }