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
//! Canonical resource-placement policy, independent from process lifetime.
//!
//! These value types use only the standard library. Selecting a mode does not
//! start a manager, register a task, or lazily launch a broker.
use std::{path::PathBuf, time::Duration};
/// Which resource boundary owns a newly launched process.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum SpawnMode {
/// Preserve direct spawning and inherited cgroup/Job Object placement.
#[default]
Inherited,
/// Require verified placement outside the requesting worker's boundary.
/// Enclosing user, container and machine limits still apply.
Independent,
}
/// Handle lifetime is not resource placement or owner-death binding.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum SpawnLifetime {
/// Stop when the returned handle is dropped normally. This is not an
/// OS-level guarantee for abrupt termination of the handle's owner.
#[default]
KillOnDrop,
/// Dropping the handle leaves a successfully committed process running.
Detached,
}
/// Explicit independent-launch authority. No implicit fallback is permitted.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum IndependentBackend {
/// Use a same-user native scheduler with this installed launcher binary.
/// Availability and actual placement must be verified at launch time.
NativeScheduler { launcher: PathBuf },
/// Connect to an already-running broker outside the worker boundary.
/// The launching process must never create this broker on demand.
ExternalBroker { endpoint: String },
}
/// Canonical spawn policy. Defaults do not require any external authority.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SpawnOptions {
pub mode: SpawnMode,
pub lifetime: SpawnLifetime,
/// Required for Independent, absent for Inherited. Conflicting selection
/// is an error rather than silently ignoring an explicit backend choice.
pub backend: Option<IndependentBackend>,
/// Combined scheduling and application-readiness budget.
pub timeout: Duration,
}
impl Default for SpawnOptions {
fn default() -> Self {
Self {
mode: SpawnMode::Inherited,
lifetime: SpawnLifetime::KillOnDrop,
backend: None,
timeout: Duration::from_secs(30),
}
}
}