Skip to main content

kaish_kernel/scheduler/
mod.rs

1//! Scheduler module for kaish — pipelines, background jobs, and scatter/gather.
2//!
3//! This module provides:
4//! - **Pipeline execution**: Run commands connected by pipes, where stdout
5//!   of one command flows to stdin of the next.
6//! - **Background jobs**: Run commands in the background with `&`, track them,
7//!   and wait for completion.
8//! - **Scatter/Gather**: Parallel fan-out and collection for pipelines.
9//!
10//! # Architecture
11//!
12//! ```text
13//! ┌─────────────────────────────────────────────────────────────┐
14//! │                     PipelineRunner                          │
15//! │  ┌─────────┐   channel   ┌─────────┐   channel   ┌────────┐│
16//! │  │ cmd1    │────────────▶│ cmd2    │────────────▶│ cmd3   ││
17//! │  │ (spawn) │   stdout    │ (spawn) │   stdout    │ (spawn)││
18//! │  └─────────┘             └─────────┘             └────────┘│
19//! └─────────────────────────────────────────────────────────────┘
20//!
21//! ┌─────────────────────────────────────────────────────────────┐
22//! │                    ScatterGatherRunner                        │
23//! │  ┌────────────┐         ┌─────────────────────────┐        │
24//! │  │ pre_scatter│────────▶│  scatter (fan-out)      │        │
25//! │  └────────────┘         │  ┌───┐ ┌───┐ ┌───┐      │        │
26//! │                         │  │ 1 │ │ 2 │ │ 3 │ ...  │        │
27//! │                         │  └───┘ └───┘ └───┘      │        │
28//! │                         │         │               │        │
29//! │                         │         ▼               │        │
30//! │                         │  gather (collect)       │        │
31//! │                         └─────────────────────────┘        │
32//! │                                    │                       │
33//! │                                    ▼                       │
34//! │                         ┌────────────┐                     │
35//! │                         │ post_gather│                     │
36//! │                         └────────────┘                     │
37//! └─────────────────────────────────────────────────────────────┘
38//!
39//! ┌─────────────────────────────────────────────────────────────┐
40//! │                      JobManager                             │
41//! │  jobs: HashMap<JobId, Job>                                  │
42//! │  - spawn(pipeline) → JobId                                  │
43//! │  - wait(JobId) → ExecResult                                 │
44//! │  - wait_all() → Vec<ExecResult>                             │
45//! │  - list() → Vec<JobInfo>                                    │
46//! └─────────────────────────────────────────────────────────────┘
47//! ```
48
49mod job;
50mod pipe_stream;
51mod pipeline;
52mod scatter;
53mod stderr_stream;
54mod stream;
55
56pub use job::{Job, JobId, JobInfo, JobManager, JobStatus};
57pub use pipe_stream::{pipe_stream, pipe_stream_default, PipeReader, PipeWriter, PIPE_BUFFER_SIZE};
58pub use stderr_stream::{stderr_stream, StderrReceiver, StderrStream};
59pub use stream::{drain_to_stream, BoundedStream, StreamStats, DEFAULT_STREAM_MAX_SIZE};
60pub use pipeline::{build_tool_args, is_bool_type, schema_param_lookup, PipelineRunner};
61pub use scatter::{
62    extract_items, parse_gather_options, parse_scatter_options, GatherOptions,
63    ScatterGatherRunner, ScatterOptions, ScatterResult,
64};