assemble_core/startup/
execution_graph.rs

1use crate::project::requests::TaskRequests;
2use crate::task::{FullTask, TaskOrderingKind};
3use parking_lot::RwLock;
4use petgraph::graph::DiGraph;
5use std::sync::Arc;
6
7/// The Execution Plan provides a plan of executable tasks that
8/// the task executor can execute.
9///
10/// For the execution plan to be valid, the following must hold:
11/// - No Cycles
12/// - The graph must be able to be topographically sorted such that all tasks that depend on a task
13///     run before a task, and all tasks that finalize a task occur after said task
14#[derive(Debug, Clone)]
15pub struct ExecutionGraph {
16    /// The task ordering graph
17    graph: Arc<RwLock<DiGraph<SharedAnyTask, TaskOrderingKind>>>,
18    /// Tasks requested
19    requested_tasks: Arc<TaskRequests>,
20}
21
22impl ExecutionGraph {
23    pub fn new(
24        graph: DiGraph<SharedAnyTask, TaskOrderingKind>,
25        requested_tasks: TaskRequests,
26    ) -> Self {
27        Self {
28            graph: Arc::new(RwLock::new(graph)),
29            requested_tasks: Arc::new(requested_tasks),
30        }
31    }
32    pub fn requested_tasks(&self) -> &Arc<TaskRequests> {
33        &self.requested_tasks
34    }
35    pub fn graph(&self) -> &Arc<RwLock<DiGraph<SharedAnyTask, TaskOrderingKind>>> {
36        &self.graph
37    }
38}
39
40pub type SharedAnyTask = Arc<RwLock<Box<dyn FullTask>>>;