dag-executor 0.1.0

A production-ready DAG executor with state management and advanced patterns
Documentation
//! Example: high-concurrency execution of thousands of tasks.
//!
//! Run with: `cargo run --release --example performance_demo`

use std::sync::Arc;
use std::time::Instant;

use dag_executor::context::Context;
use dag_executor::prelude::*;

#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
    const N: usize = 10_000;

    let mut dag = Dag::new();
    dag.add_task(Arc::new(BasicTask::new("root", |_: Arc<Context>| async {
        Ok(serde_json::Value::Null)
    })))?;
    for i in 0..N {
        dag.add_task(Arc::new(
            BasicTask::new(format!("t{i}"), |_: Arc<Context>| async {
                Ok(serde_json::json!(1))
            })
            .with_deps(["root"]),
        ))?;
    }

    let executor = DagExecutor::builder()
        .persist(false)
        .concurrency(1024)
        .build();

    let started = Instant::now();
    let report = executor.run(dag).await?;
    let elapsed = started.elapsed();

    let total = report.records.len();
    let per_sec = total as f64 / elapsed.as_secs_f64();
    println!("executed {total} tasks in {elapsed:?}");
    println!("throughput: {per_sec:.0} tasks/second");
    println!("success: {}", report.is_success());
    Ok(())
}