package camlix
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
md5=0b306dd21a38f2d5c302d77bdbf2e4d2
sha512=812e9959b551c152f37ed17f0e2f010b13f91b561e07846136a699e3cefaa383013e4a30ded72c64dcac49f6136581330a126d57c4db1c60ff654081b5339d08
Description
Camlix is a simple circuit breaker library for ocaml
Added to opam-repository:
README
camlix
Camlix is a simple circuit breaker library for ocaml
Usage
Simple command
open Core
open Camlix
exception TooLarge of string
let double_if_lt_ten n =
if n > 10 then
Error (TooLarge "Larger 10")
else
Ok (n * 2)
;;
(* Define a simple circuit breaker *)
let cmd = Command.create (Config.create ()) ~f:double_if_lt_ten;;
(* and run it with an example input *)
let result = Command.run cmd 10;;
assert ((Result.ok_exn result) = 20)Command with fallback
open Core
open Camlix
exception TooLarge of string
let double_if_lt_ten n =
if n > 10 then
Error (TooLarge "Larger 10")
else
Ok (n * 2)
;;
(* Define a circuit breaker command with a fallback function *)
let cmd = Command.create_with_fallback (Config.create ()) ~f:double_if_lt_ten ~fb:(fun _ -> 4);;
(* and run it with an example input *)
let result = Command.run cmd 11;;
assert ((Result.ok_exn result) = 4)Command with custom configuration
open Core
open Camlix
let config = { (Config.create ()) with
error_threshold = 10;
error_threshold_percentage = 50;
buckets_in_window = 10;
bucket_size_in_ms = 1000;
circuit_open_ms = 5000;
}
exception TooLarge of string
let double_if_lt_ten n =
if n > 10 then
Error (TooLarge "Larger 10")
else
Ok (n * 2)
;;
(* Define a circuit breaker command with custom configuration *)
let cmd = Command.create_with_fallback config ~f:double_if_lt_ten ~fb:(fun _ -> 4);;
(* and run it with an example input *)
let result = Command.run cmd 10;;
assert ((Result.ok_exn result) = 20)Command with custom rejection error
By default the error type is exn as an ExecutionRejected exception is used when the circuit is open. If you want a different error type you can use the run_with_custom_rejection function:
open Core
open Camlix
let double_if_lt_ten n =
if n > 10 then
Error "Larger 10"
else
Ok (n * 2)
;;
(* Define a simple circuit breaker *)
let cmd = Command.create (Config.create ()) ~f:double_if_lt_ten;;
(* and run it with an example input providing a custom rejection *)
let result = Command.run_with_custom_rejection cmd 10 "Just using a string here";;
assert ((Result.ok_or_failwith result) = 20)Configuration
circuit_open_ms - Time in ms commands are rejected after the circuit opened - Default 5000
error_threshold - Minimum amount of errors for the circuit to break - Default 10
error_threshold_percentage - Minimum error percentage for the circuit to break - Default 50
buckets_in_window - Rolling window to track success/error calls, this property defines the amount of buckets in a window (buckets_in_window * bucket_size_in_ms is the overall length in ms of the window) - Default 10
bucket_size_in_ms - This property defines the ms a bucket is long, i.e. each x ms a new bucket will be created (buckets_in_window * bucket_size_in_ms is the overall length in ms of the window) - Default 1000
circuit_breaker_enabled - Defines if the circuit breaker is enabled or not - Default true
Dependencies (5)
- ppx_jane
- ppx_compare
- core
-
dune
>= "2.9.0" -
ocaml
>= "4.10.0"
Dev Dependencies (1)
-
alcotest
with-test
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building camlix with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.1 (this version) | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure