-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow configurign top-level supervisor restart limits
This lets you start a runtime that will terminate if the top-level application terminates, which is useful for CLIs that may crash and need to stay crashed. For long-running applications this helps configure how many times you want the application to retry before fully shutting down. Also add a small pretty printer to print out the config as debug information when the runtime starts.
- Loading branch information
Showing
3 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
type t = { rnd : Random.State.t; max_workers : int; workers : int } | ||
type t = { | ||
rnd : Random.State.t; | ||
max_workers : int; | ||
workers : int; | ||
supervisor_restart_limit : int; | ||
supervisor_restart_period : int; | ||
} | ||
|
||
let make ?workers () = | ||
let pp fmt t = | ||
Format.fprintf fmt "== RIOT CONFIG ==\n"; | ||
Format.fprintf fmt "* max_wokers=%d\n" t.max_workers; | ||
Format.fprintf fmt "* workers=%d\n" t.workers; | ||
Format.fprintf fmt "* supervisor_restart_limit=%d\n" t.supervisor_restart_limit; | ||
Format.fprintf fmt "* supervisor_restart_period=%d\n" t.supervisor_restart_period; | ||
Format.fprintf fmt "\n%!" | ||
;; | ||
|
||
let make ?(supervisor_restart_limit = 1) ?(supervisor_restart_period = 0) | ||
?workers () = | ||
let max_workers = Int.max 0 (Stdlib.Domain.recommended_domain_count () - 2) in | ||
let workers = | ||
match workers with Some w -> Int.min w max_workers | None -> max_workers | ||
in | ||
let rnd = Random.State.make_self_init () in | ||
{ rnd; max_workers; workers } | ||
{ | ||
rnd; | ||
max_workers; | ||
workers; | ||
supervisor_restart_limit; | ||
supervisor_restart_period; | ||
} | ||
|
||
let default () = make () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters