Circuit breaker state transitions
Review this Python circuit breaker. When open, after a cooldown it moves to half-open and lets calls through to test recovery.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1class Breaker:
2 def call(self, fn):
3 if self.state == "open":
4 if time.time() - self.opened_at >= self.cooldown:
5 self.state = "half_open"
6 else:
7 raise BreakerOpen()
8 try:
9 r = fn()
10 self.state = "closed"; self.failures = 0
11 return r
12 except Exception:
13 self.failures += 1
14 self.state = "open"; self.opened_at = time.time()
15 raise
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.