Expand description
Scheduler module for kaish — pipelines, background jobs, and scatter/gather.
This module provides:
- Pipeline execution: Run commands connected by pipes, where stdout of one command flows to stdin of the next.
- Background jobs: Run commands in the background with
&, track them, and wait for completion. - Scatter/Gather: Parallel fan-out and collection for pipelines.
§Architecture
┌─────────────────────────────────────────────────────────────┐
│ PipelineRunner │
│ ┌─────────┐ channel ┌─────────┐ channel ┌────────┐│
│ │ cmd1 │────────────▶│ cmd2 │────────────▶│ cmd3 ││
│ │ (spawn) │ stdout │ (spawn) │ stdout │ (spawn)││
│ └─────────┘ └─────────┘ └────────┘│
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ ScatterGatherRunner │
│ ┌────────────┐ ┌─────────────────────────┐ │
│ │ pre_scatter│────────▶│ scatter (fan-out) │ │
│ └────────────┘ │ ┌───┐ ┌───┐ ┌───┐ │ │
│ │ │ 1 │ │ 2 │ │ 3 │ ... │ │
│ │ └───┘ └───┘ └───┘ │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ gather (collect) │ │
│ └─────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────┐ │
│ │ post_gather│ │
│ └────────────┘ │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ JobManager │
│ jobs: HashMap<JobId, Job> │
│ - spawn(pipeline) → JobId │
│ - wait(JobId) → ExecResult │
│ - wait_all() → Vec<ExecResult> │
│ - list() → Vec<JobInfo> │
└─────────────────────────────────────────────────────────────┘Structs§
- Bounded
Stream - A bounded stream backed by a ring buffer.
- Gather
Options - Options for gather operation.
- Job
- A background job.
- JobId
- Unique identifier for a background job.
- JobInfo
- Information about a job for listing.
- JobManager
- Manager for background jobs.
- Pipe
Reader - Reading end of a pipe stream.
- Pipe
Writer - Writing end of a pipe stream.
- Pipeline
Runner - Runs pipelines by spawning tasks and connecting them via channels.
- Scatter
Gather Runner - Runs scatter/gather pipelines.
- Scatter
Options - Options for scatter operation.
- Scatter
Result - Result from a single scatter worker.
- Stderr
Receiver - Receiving end of the stderr stream.
- Stderr
Stream - Cloneable handle to the kernel’s stderr output stream.
- Stream
Stats - Statistics about a bounded stream.
Enums§
- JobStatus
- Status of a background job.
Constants§
- DEFAULT_
STREAM_ MAX_ SIZE - Default maximum size for bounded streams (10MB).
- PIPE_
BUFFER_ SIZE - Default pipe buffer capacity (matches Linux kernel pipe default).
Functions§
- build_
tool_ args - Build ToolArgs from AST Args, evaluating expressions.
- drain_
to_ stream - Drain an async reader into a bounded stream.
- extract_
items - Extract items from structured data or text.
- is_
bool_ type - Check if a type is considered boolean.
- parse_
gather_ options - Parse gather options from tool args.
- parse_
scatter_ options - Parse scatter options from tool args.
- pipe_
stream - Create a bounded pipe stream pair with the given capacity.
- pipe_
stream_ default - Create a pipe stream pair with the default capacity (64KB).
- schema_
param_ lookup - Extract parameter types from a tool schema.
- stderr_
stream - Create a new stderr stream pair.