Exemplo n.º 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
            ILogger log,
            [DurableClient] IDurableOrchestrationClient orchestrationClient
            )
        {
            if (!await durableCircuitBreakerClient.IsExecutionPermitted(CircuitBreakerId, log, (IDurableClient)orchestrationClient))
            {
                log?.LogError($"{nameof(FooFragileFunctionWithCircuitBreaker)}: Service unavailable.");

                return(new StatusCodeResult((int)HttpStatusCode.ServiceUnavailable));
            }

            try
            {
                var result = await Foo.DoFragileWork(req, log, "circuit breaker, performance priority");

                await durableCircuitBreakerClient.RecordSuccess(CircuitBreakerId, log, (IDurableClient)orchestrationClient);

                return(result);
            }
            catch (Exception exception)
            {
                await durableCircuitBreakerClient.RecordFailure(CircuitBreakerId, log, (IDurableClient)orchestrationClient);

                log?.LogError(exception, $"{nameof(FooFragileFunctionWithCircuitBreaker)}: Exception: {exception.Message}");

                return(new InternalServerErrorResult());
            }
        }
Exemplo n.º 2
0
 public async Task <IActionResult> IsExecutionPermitted(
     [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "DurableCircuitBreaker/{circuitBreakerId:alpha}/IsExecutionPermitted")] HttpRequestMessage req,
     // GET http method left accessible for easy demonstration from a browser. Conceptually, even IsExecutionPermitted may change circuit state (to Half-Open), so might be considered POST-only.
     string circuitBreakerId,
     ILogger log,
     [DurableClient] IDurableClient durableClient
     )
 {
     return(new OkObjectResult(await durableCircuitBreakerClient.IsExecutionPermitted(circuitBreakerId, log, durableClient)));
 }