Skip to main content

running_process/
spawn_contract.rs

1//! Canonical resource-placement policy, independent from process lifetime.
2//!
3//! These value types use only the standard library. Selecting a mode does not
4//! start a manager, register a task, or lazily launch a broker.
5
6use std::{path::PathBuf, time::Duration};
7
8/// Which resource boundary owns a newly launched process.
9#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
10pub enum SpawnMode {
11    /// Preserve direct spawning and inherited cgroup/Job Object placement.
12    #[default]
13    Inherited,
14    /// Require verified placement outside the requesting worker's boundary.
15    /// Enclosing user, container and machine limits still apply.
16    Independent,
17}
18
19/// Handle lifetime is not resource placement or owner-death binding.
20#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
21pub enum SpawnLifetime {
22    /// Stop when the returned handle is dropped normally. This is not an
23    /// OS-level guarantee for abrupt termination of the handle's owner.
24    #[default]
25    KillOnDrop,
26    /// Dropping the handle leaves a successfully committed process running.
27    Detached,
28}
29
30/// Explicit independent-launch authority. No implicit fallback is permitted.
31#[derive(Clone, Debug, Eq, PartialEq)]
32pub enum IndependentBackend {
33    /// Use a same-user native scheduler with this installed launcher binary.
34    /// Availability and actual placement must be verified at launch time.
35    NativeScheduler { launcher: PathBuf },
36    /// Connect to an already-running broker outside the worker boundary.
37    /// The launching process must never create this broker on demand.
38    ExternalBroker { endpoint: String },
39}
40
41/// Canonical spawn policy. Defaults do not require any external authority.
42#[derive(Clone, Debug, Eq, PartialEq)]
43pub struct SpawnOptions {
44    pub mode: SpawnMode,
45    pub lifetime: SpawnLifetime,
46    /// Required for Independent, absent for Inherited. Conflicting selection
47    /// is an error rather than silently ignoring an explicit backend choice.
48    pub backend: Option<IndependentBackend>,
49    /// Combined scheduling and application-readiness budget.
50    pub timeout: Duration,
51}
52
53impl Default for SpawnOptions {
54    fn default() -> Self {
55        Self {
56            mode: SpawnMode::Inherited,
57            lifetime: SpawnLifetime::KillOnDrop,
58            backend: None,
59            timeout: Duration::from_secs(30),
60        }
61    }
62}