pub struct ChildSpec {
pub name: String,
pub function: u32,
pub args: Vec<Value>,
pub restart: RestartPolicy,
}Expand description
A child the supervisor should start (and possibly restart).
function is an index into the runtime’s chunk — the same number
super::runtime::Runtime::spawn takes. Args are cloned on every
restart so a child always comes back with the original call.
Fields§
§name: String§function: u32§args: Vec<Value>§restart: RestartPolicyImplementations§
Source§impl ChildSpec
impl ChildSpec
Sourcepub fn new(name: impl Into<String>, function: u32) -> Self
pub fn new(name: impl Into<String>, function: u32) -> Self
Examples found in repository?
examples/crash_and_restart.rs (line 46)
15fn main() {
16 let rt = match Runtime::with_config(
17 samples::boom(),
18 RuntimeConfig {
19 workers: 1,
20 quantum: 1_000,
21 },
22 ) {
23 Ok(rt) => rt,
24 Err(e) => {
25 eprintln!("runtime: {e}");
26 std::process::exit(1);
27 }
28 };
29 let Some(boom) = rt.function_index("boom") else {
30 eprintln!("missing boom");
31 std::process::exit(1);
32 };
33 let sup = match Supervisor::with_config(
34 rt.spawner(),
35 SupervisorConfig {
36 max_restarts: 2,
37 max_period: Duration::from_secs(5),
38 },
39 ) {
40 Ok(s) => s,
41 Err(e) => {
42 eprintln!("supervisor: {e}");
43 std::process::exit(1);
44 }
45 };
46 if let Err(e) = sup.start_child(ChildSpec::new("boom", boom).restart(RestartPolicy::OnFailure))
47 {
48 eprintln!("start_child: {e}");
49 std::process::exit(1);
50 }
51
52 let start = std::time::Instant::now();
53 while !sup.intensity_exceeded() {
54 if start.elapsed() > Duration::from_secs(2) {
55 eprintln!("supervisor did not hit intensity in time");
56 std::process::exit(1);
57 }
58 thread::sleep(Duration::from_millis(5));
59 }
60
61 let metrics = rt.metrics();
62 println!("intensity exceeded after {} failures", metrics.processes_failed);
63 println!("{metrics}");
64 sup.shutdown();
65 rt.shutdown();
66}pub fn args(self, args: Vec<Value>) -> Self
Sourcepub fn restart(self, restart: RestartPolicy) -> Self
pub fn restart(self, restart: RestartPolicy) -> Self
Examples found in repository?
examples/crash_and_restart.rs (line 46)
15fn main() {
16 let rt = match Runtime::with_config(
17 samples::boom(),
18 RuntimeConfig {
19 workers: 1,
20 quantum: 1_000,
21 },
22 ) {
23 Ok(rt) => rt,
24 Err(e) => {
25 eprintln!("runtime: {e}");
26 std::process::exit(1);
27 }
28 };
29 let Some(boom) = rt.function_index("boom") else {
30 eprintln!("missing boom");
31 std::process::exit(1);
32 };
33 let sup = match Supervisor::with_config(
34 rt.spawner(),
35 SupervisorConfig {
36 max_restarts: 2,
37 max_period: Duration::from_secs(5),
38 },
39 ) {
40 Ok(s) => s,
41 Err(e) => {
42 eprintln!("supervisor: {e}");
43 std::process::exit(1);
44 }
45 };
46 if let Err(e) = sup.start_child(ChildSpec::new("boom", boom).restart(RestartPolicy::OnFailure))
47 {
48 eprintln!("start_child: {e}");
49 std::process::exit(1);
50 }
51
52 let start = std::time::Instant::now();
53 while !sup.intensity_exceeded() {
54 if start.elapsed() > Duration::from_secs(2) {
55 eprintln!("supervisor did not hit intensity in time");
56 std::process::exit(1);
57 }
58 thread::sleep(Duration::from_millis(5));
59 }
60
61 let metrics = rt.metrics();
62 println!("intensity exceeded after {} failures", metrics.processes_failed);
63 println!("{metrics}");
64 sup.shutdown();
65 rt.shutdown();
66}Trait Implementations§
Auto Trait Implementations§
impl Freeze for ChildSpec
impl RefUnwindSafe for ChildSpec
impl Send for ChildSpec
impl Sync for ChildSpec
impl Unpin for ChildSpec
impl UnsafeUnpin for ChildSpec
impl UnwindSafe for ChildSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more