public async Task <BreakerState> GetBreakerState(string circuitBreakerId, ILogger log,
                                                         IDurableClient durableClient)
        {
            log?.LogCircuitBreakerMessage(circuitBreakerId, $"Getting breaker state for circuit-breaker = '{circuitBreakerId}'.");

            var readState = await durableClient.ReadEntityStateAsync <BreakerState>(DurableCircuitBreakerEntity.GetEntityId(circuitBreakerId));

            // We present a not-yet-initialized circuit-breaker as null (it will be initialized when successes or failures are first posted against it).
            return(readState.EntityExists && readState.EntityState != null ? readState.EntityState : null);
        }
        public async Task <CircuitState> GetCircuitState(string circuitBreakerId, ILogger log,
                                                         IDurableClient durableClient)
        {
            log?.LogCircuitBreakerMessage(circuitBreakerId, $"Getting circuit state for circuit-breaker = '{circuitBreakerId}'.");

            var readState = await durableClient.ReadEntityStateAsync <BreakerState>(DurableCircuitBreakerEntity.GetEntityId(circuitBreakerId));

            // To keep the return type simple, we present a not-yet-initialized circuit-breaker as closed (it will be closed when first used).
            return(readState.EntityExists && readState.EntityState != null ? readState.EntityState.CircuitState : CircuitState.Closed);
        }
Example #3
0
        public async Task <bool> IsExecutionPermitted(string breakerId, ILogger log, IDurableOrchestrationContext orchestrationContext)
        {
            if (string.IsNullOrEmpty(breakerId))
            {
                throw new ArgumentNullException($"{nameof(breakerId)}");
            }

            log?.LogCircuitBreakerMessage(breakerId, $"Asking IsExecutionPermitted (consistency priority) for circuit-breaker = '{breakerId}'.");

            return(await orchestrationContext.CallEntityAsync <bool>(DurableCircuitBreakerEntity.GetEntityId(breakerId), DurableCircuitBreakerEntity.Operation.IsExecutionPermitted));
        }
        public async Task RecordFailure(string circuitBreakerId, ILogger log, IDurableClient durableClient)
        {
            log?.LogCircuitBreakerMessage(circuitBreakerId, $"Recording failure for circuit-breaker = '{circuitBreakerId}'.");

            await durableClient.SignalEntityAsync(DurableCircuitBreakerEntity.GetEntityId(circuitBreakerId), DurableCircuitBreakerEntity.Operation.RecordFailure);
        }
Example #5
0
        public async Task <BreakerState> GetBreakerState(string circuitBreakerId, ILogger log, IDurableOrchestrationContext orchestrationContext)
        {
            log?.LogCircuitBreakerMessage(circuitBreakerId, $"Getting breaker state for circuit-breaker = '{circuitBreakerId}'.");

            return(await orchestrationContext.CallEntityAsync <BreakerState>(DurableCircuitBreakerEntity.GetEntityId(circuitBreakerId), DurableCircuitBreakerEntity.Operation.GetBreakerState));
        }
Example #6
0
        public async Task RecordFailure(string circuitBreakerId, ILogger log, IDurableOrchestrationContext orchestrationContext)
        {
            log?.LogCircuitBreakerMessage(circuitBreakerId, $"Recording failure for circuit-breaker = '{circuitBreakerId}'.");

            await orchestrationContext.CallEntityAsync(DurableCircuitBreakerEntity.GetEntityId(circuitBreakerId), DurableCircuitBreakerEntity.Operation.RecordFailure);
        }