1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! # Restart policies for task actors.
//!
//! [`RestartPolicy`] determines whether a task should be restarted after it finishes or fails.
//! - [`RestartPolicy::Always`] the task is restarted unconditionally, with optional delay between successful completions.
//! - [`RestartPolicy::OnFailure`] the task is restarted only if it fails (default).
//! - [`RestartPolicy::Never`] the task runs once and is never restarted.
//!
//! ## Choosing the right policy
//!
//! **One-shot tasks** (run once, exit):
//! ```text
//! RestartPolicy::Never → Task runs once, exits permanently
//! ```
//!
//! **Periodic tasks** (complete, wait, repeat):
//! ```text
//! RestartPolicy::Always {
//! interval: Some(Duration) → Task runs, waits interval, repeats
//! }
//! ```
//!
//! **Long-running tasks** (infinite loop inside):
//! ```text
//! RestartPolicy::OnFailure → Task crashes → restart with backoff
//! RestartPolicy::Always {
//! interval: None → Task exits (success/fail) → restart immediately
//! }
//! ```
//!
//! **Failure recovery**:
//! ```text
//! RestartPolicy::OnFailure → Restart only on errors (default)
//! ```
/// Policy controlling whether a task is restarted after completion or failure.
///
/// # Also
///
/// - [`BackoffPolicy`](crate::BackoffPolicy) - how retry delays grow between attempts
/// - [`JitterPolicy`](crate::JitterPolicy) - randomization strategy for backoff delays
/// - [`TaskSpec`](crate::TaskSpec) - wires restart + backoff + timeout together