Skip to main content

elfo_pinger/
lib.rs

1//! Periodically pings all actors in the topology to check if they are alive.
2//! [Configuration].
3//!
4//! [Configuration]: config::Config
5
6#![cfg_attr(docsrs, feature(doc_cfg))]
7
8use std::time::Duration;
9
10use elfo_core::{ActorGroup, Blueprint, RestartParams, RestartPolicy, Topology};
11
12pub mod config;
13
14mod actor;
15
16/// Creates a blueprint.
17///
18/// # Example
19/// ```
20/// # use elfo_core as elfo;
21/// let topology = elfo::Topology::empty();
22/// let pingers = topology.local("pingers");
23///
24/// // Usually, it's `elfo::batteries::pinger::fixture`.
25/// pingers.mount(elfo_pinger::new(&topology));
26/// ```
27pub fn new(topology: &Topology) -> Blueprint {
28    let topology = topology.clone();
29    ActorGroup::new()
30        .config::<config::Config>()
31        .restart_policy(RestartPolicy::on_failure(RestartParams::new(
32            Duration::from_secs(5),
33            Duration::from_secs(30),
34        )))
35        .stop_order(100)
36        .exec(move |ctx| actor::exec(ctx, topology.clone()))
37}