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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//! # solti-model
//!
//! Domain model for the solti task execution system.
//!
//! This crate defines the core resource types.
//!
//! ## Architecture
//!
//! ```text
//! ┌──────────────────────────────────────────────────────────┐
//! │ Task │
//! │ │
//! │ ObjectMeta TaskSpec TaskStatus │
//! │ ├─ id: TaskId ├─ slot: Slot ├─ phase │
//! │ ├─ resource_version ├─ kind: TaskKind ├─ attempt │
//! │ ├─ created_at ├─ timeout ├─ exit_code │
//! │ └─ updated_at ├─ restart └─ error │
//! │ ├─ backoff │
//! │ ├─ admission │
//! │ ├─ runner_selector │
//! │ └─ labels │
//! └──────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Resource model
//!
//! | Section | Type | Responsibility |
//! |-----------------|------------------|-----------------------------------------------------------------|
//! | **metadata** | [`ObjectMeta`] | Identity, versioning, timestamps |
//! | **status** | [`TaskStatus`] | Observed state: phase, attempt count, exit code, last error |
//! | **spec** | [`TaskSpec`] | Desired state (private fields; build via [`TaskSpec::builder`]) |
//!
//! Slot and labels live in `spec` as the single source of truth.
//! [`Task`] provides convenience accessors ([`Task::slot`], [`Task::labels`]) that delegate to `spec`.
//!
//! ## Versioning
//!
//! [`ObjectMeta::resource_version`] is a monotonic counter bumped on every change
//! (spec or status) for optimistic concurrency.
//!
//! ## Task lifecycle
//!
//! ```text
//! Pending ──► Running ──► Succeeded
//! │
//! ├──► Failed ──► (restart) ──► Running
//! ├──► Timeout
//! ├──► Canceled
//! └──► Exhausted (max retries reached)
//! ```
//!
//! Terminal phases: `Succeeded`, `Failed`, `Timeout`, `Canceled`, `Exhausted`.
//! See [`TaskPhase::is_terminal`].
//!
//! ## Task kinds
//!
//! [`TaskKind`] defines what a task actually runs:
//!
//! | Variant | Description |
//! |----------------|------------------------------------------------------|
//! | `Subprocess` | External process (`command`, `args`, `env`, `cwd`) |
//! | `Wasm` | WebAssembly module |
//! | `Container` | OCI container image |
//! | `Embedded` | Code-defined task (in-process `TaskRef`) |
//!
//! `Subprocess` tasks go through `solti_runner::RunnerRouter`; `Embedded` tasks
//! are submitted directly via `SupervisorApi::submit_with_task`.
//!
//! ## Policies
//!
//! | Policy | Controls |
//! |----------------------|----------------------------------------------------------|
//! | [`RestartPolicy`] | When to restart: `Never`, `OnFailure`, `Always` |
//! | [`BackoffPolicy`] | Delay between retries: initial, max, factor, jitter |
//! | [`JitterPolicy`] | Jitter strategy: `None`, `Full`, `Equal`, `Decorrelated` |
//! | [`AdmissionPolicy`] | Duplicate handling: `DropIfRunning`, `Replace`, `Queue` |
//!
//! ## Construction
//!
//! [`TaskSpec`] fields are private; construct via [`TaskSpec::builder`]:
//!
//! ```text
//! let spec = TaskSpec::builder("my-slot", kind, 5_000u64)
//! .restart(RestartPolicy::OnFailure)
//! .build()?;
//! ```
//!
//! See [`TaskSpecBuilder`] for the full API.
//!
//! ## Also
//!
//! - `solti-runner` consumes [`TaskSpec`] and [`TaskKind`] to build executable tasks.
//! - `solti-core` manages [`Task`] lifecycle and state transitions.
//! - `solti-api` serializes/deserializes model types over gRPC and HTTP.
//!
//! ## Domain types
//!
//! | Type | Description |
//! |--------------------|-----------------------------------------------------------|
//! | [`Slot`] | Logical execution lane (newtype over `Arc<str>`) |
//! | [`TaskId`] | Unique task identifier (newtype over `Arc<str>`) |
//! | [`Timeout`] | Per-attempt timeout in milliseconds |
//! | [`Labels`] | Key-value metadata for routing and filtering |
//! | [`TaskEnv`] | Ordered environment variables for task execution |
//! | [`Flag`] | Boolean toggle with `enabled()`/`disabled()` constructors |
//! | [`TaskQuery`] | Builder for filtered, paginated task listing |
//! | [`TaskPage`] | Paginated query result |
//! | [`TaskSpecBuilder`]| Validated builder for [`TaskSpec`] |
//!
//! ## Example
//!
//! ```rust
//! use solti_model::{
//! BackoffPolicy, JitterPolicy,
//! RestartPolicy, SubprocessMode, SubprocessSpec, Task, TaskKind, TaskPhase, TaskSpec,
//! };
//!
//! // 1) Build a task spec via the builder
//! let spec = TaskSpec::builder(
//! "my-worker",
//! TaskKind::Subprocess(SubprocessSpec {
//! mode: SubprocessMode::Command {
//! command: "echo".into(),
//! args: vec!["hello".into()],
//! },
//! env: Default::default(),
//! cwd: None,
//! fail_on_non_zero: Default::default(),
//! }),
//! 5_000u64,
//! )
//! .restart(RestartPolicy::OnFailure)
//! .backoff(BackoffPolicy {
//! jitter: JitterPolicy::Equal,
//! first_ms: 1_000,
//! max_ms: 30_000,
//! factor: 2.0,
//! })
//! .build()
//! .expect("spec should be valid");
//!
//! // 2) Validate at submit boundary (checks business rules like no Embedded)
//! spec.validate().expect("spec should pass submit validation");
//!
//! // 3) Create a task resource (normally done by the supervisor)
//! let task = Task::new("task-001".into(), spec);
//! assert_eq!(task.slot(), "my-worker");
//! assert_eq!(*task.phase(), TaskPhase::Pending);
//! assert_eq!(task.metadata().resource_version, 1);
//! ```
pub use ;
pub use ;
pub use ;