dag-executor 0.1.0

A production-ready DAG executor with state management and advanced patterns
Documentation
//! The core [`Task`] abstraction.

use crate::context::Context;
use crate::error::TaskError;
use async_trait::async_trait;
use std::sync::Arc;

/// The value a task produces on success.
pub type TaskOutput = serde_json::Value;

/// A unit of work in the DAG.
///
/// Implementations must be `Send + Sync` because tasks are shared across worker
/// threads (`Arc<dyn Task>`) and executed concurrently. The default
/// [`Task::dependencies`] and [`Task::priority`] make leaf, normal-priority
/// tasks the zero-boilerplate case.
#[async_trait]
pub trait Task: Send + Sync {
    /// Stable, unique identifier for this task within a DAG.
    fn id(&self) -> &str;

    /// Ids of tasks that must complete successfully before this one runs.
    fn dependencies(&self) -> Vec<String> {
        Vec::new()
    }

    /// Scheduling priority; higher values are scheduled first among ready tasks.
    fn priority(&self) -> u8 {
        0
    }

    /// Execute the task.
    ///
    /// The returned future is run on the executor's worker pool. Implementations
    /// should periodically check [`Context::is_cancelled`] for long-running work.
    async fn execute(&self, ctx: Arc<Context>) -> Result<TaskOutput, TaskError>;
}