MCPcopy Index your code
hub / github.com/akhercha/task-supervisor

github.com/akhercha/task-supervisor @0.4.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.4.1 ↗ · + Follow
99 symbols 372 edges 15 files 11 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

task-supervisor

Crates.io Docs.rs

task-supervisor helps you keep Tokio tasks alive. It watches each task, restarts it if it crashes or stops responding, and lets you add, restart, or kill tasks at runtime.

Install

cargo add task-supervisor

Quick example

use task_supervisor::{SupervisorBuilder, SupervisedTask, TaskResult};

#[derive(Clone)]
struct Printer;

impl SupervisedTask for Printer {
    async fn run(&mut self) -> TaskResult {w
        println!("hello");
        Ok(())
    }
}

#[tokio::main]
async fn main() {
    let supervisor = SupervisorBuilder::default()
        .with_task("printer", Printer)
        .build()
        .run();

    supervisor.wait().await.unwrap();   // wait until every task finishes or is killed
}

What you get

  • Automatic restarts – failed tasks are relaunched with exponential back-off.
  • Dynamic control – add, restart, kill, or query tasks at runtime through a SupervisorHandle.
  • Configurable – health-check interval, restart limits, back-off, dead-task threshold.

Usage

Build a supervisor with SupervisorBuilder, call .build() to get a Supervisor, then .run() to start it. This returns a SupervisorHandle you use to control things at runtime:

Method Description
wait().await Block until the supervisor exits
add_task(name, task) Register and start a new task
restart(name) Force-restart a task
kill_task(name) Stop a task permanently
get_task_status(name).await Get a task's TaskStatus
get_all_task_statuses().await Get every task's status
shutdown() Stop all tasks and exit

The handle auto-shuts down the supervisor when all clones are dropped.

Clone and restart behaviour

Every task must implement Clone. The supervisor stores the original instance and clones it each time the task is started or restarted. Mutations made through &mut self in run() only affect the running clone and are lost on restart.

To share state across restarts, wrap it in an Arc (e.g. Arc<AtomicUsize>). Plain owned fields will always start from their original value. See the SupervisedTask docs for a full example.

License

MIT

Extension points exported contracts — how you extend this code

SupervisedTask (Interface)
The trait users implement for tasks managed by the supervisor. # Clone and restart semantics The supervisor stores the [8 …
src/task/mod.rs
DynSupervisedTask (Interface)
Dyn-compatible wrapper for `SupervisedTask`. Not user-facing. [1 implementers]
src/task/mod.rs

Core symbols most depended-on inside this repo

get_task_status
called by 29
src/supervisor/handle.rs
add_task
called by 27
src/supervisor/handle.rs
build
called by 17
src/supervisor/builder.rs
with_base_restart_delay
called by 11
src/supervisor/builder.rs
with_max_restart_attempts
called by 10
src/supervisor/builder.rs
mark
called by 9
src/task/mod.rs
with_health_check_interval
called by 8
src/supervisor/builder.rs
shutdown
called by 7
src/supervisor/handle.rs

Shape

Method 54
Function 25
Class 13
Enum 5
Interface 2

Languages

Rust100%

Modules by API surface

src/supervisor/mod.rs18 symbols
src/task/mod.rs17 symbols
src/supervisor/handle.rs14 symbols
src/supervisor/builder.rs12 symbols
tests/test_tasks.rs9 symbols
tests/test_handle.rs6 symbols
tests/common/mod.rs6 symbols
tests/test_supervisor.rs4 symbols
tests/test_clone_semantics.rs4 symbols
examples/simple.rs3 symbols
tests/test_wait.rs2 symbols
tests/test_threshold.rs2 symbols

For agents

$ claude mcp add task-supervisor \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact