Message_templates.Circuit_breakerCircuit breaker pattern for error recovery
The circuit breaker prevents cascade failures by temporarily blocking calls when failures exceed a threshold. It has three states:
Example:
let cb =
Circuit_breaker.create ~failure_threshold:5 ~reset_timeout_ms:30000 ()
in
(* Protected call *)
let success = Circuit_breaker.call cb (fun () -> risky_operation ()) in
if not success then
Printf.printf "Circuit is open, request rejected\n"