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

            var readState = await durableClient.ReadEntityStateAsync <DurableCircuitBreaker>(DurableCircuitBreaker.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).
            if (!readState.EntityExists || readState.EntityState == null)
            {
                return(null);
            }

            return(readState.EntityState);
        }
Example #2
0
        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 <DurableCircuitBreaker>(DurableCircuitBreaker.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);
        }