jev_circuit.mojo (936B)
1 @fieldwise_init 2 struct CircuitState(Copyable, Movable): 3 var open: Bool 4 var consecutive_failures: Int 5 var threshold: Int 6 7 8 def circuit_state(threshold: Int) raises -> CircuitState: 9 if threshold <= 0: 10 raise Error("circuit threshold must be positive") 11 return CircuitState(open=False, consecutive_failures=0, threshold=threshold) 12 13 14 def circuit_record_success(state: CircuitState) -> CircuitState: 15 return CircuitState( 16 open=False, consecutive_failures=0, threshold=state.threshold 17 ) 18 19 20 def circuit_record_failure(state: CircuitState) -> CircuitState: 21 var failures = state.consecutive_failures + 1 22 return CircuitState( 23 open=failures >= state.threshold, 24 consecutive_failures=failures, 25 threshold=state.threshold, 26 ) 27 28 29 def circuit_allows(state: CircuitState) -> Bool: 30 return not state.open 31 32 33 def process_liveness_is_provider_readiness() -> Bool: 34 return False