mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-07 18:37:56 -05:00
feat: for exponential backoff
This commit is contained in:
parent
f519f2f49f
commit
64c7125838
2 changed files with 25 additions and 0 deletions
13
src/client/util_backoff.ml
Normal file
13
src/client/util_backoff.ml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
type t = {
|
||||
mutable delay_s: float;
|
||||
min_delay_s: float;
|
||||
max_delay_s: float;
|
||||
}
|
||||
|
||||
let create () = { delay_s = 0.001; min_delay_s = 0.001; max_delay_s = 20. }
|
||||
|
||||
let on_success self = self.delay_s <- max self.min_delay_s (self.delay_s /. 10.)
|
||||
|
||||
let on_error self = self.delay_s <- min self.max_delay_s (self.delay_s *. 2.)
|
||||
|
||||
let[@inline] cur_duration_s self = self.delay_s
|
||||
12
src/client/util_backoff.mli
Normal file
12
src/client/util_backoff.mli
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
(** Backoff behavior in case of errors *)
|
||||
|
||||
type t
|
||||
(** Backoff state. Not thread safe *)
|
||||
|
||||
val create : unit -> t
|
||||
|
||||
val on_success : t -> unit
|
||||
|
||||
val on_error : t -> unit
|
||||
|
||||
val cur_duration_s : t -> float
|
||||
Loading…
Add table
Reference in a new issue