dataflow_rs/engine/task.rs
1//! # Task Module
2//!
3//! This module defines the `Task` structure, which represents a single
4//! processing unit within a workflow. Tasks are the fundamental building
5//! blocks of data processing pipelines.
6
7use crate::engine::functions::FunctionConfig;
8use serde::Deserialize;
9use serde_json::Value;
10
11/// A single processing unit within a workflow.
12///
13/// Tasks execute functions with optional conditions and error handling.
14/// They are processed sequentially within a workflow, allowing later tasks
15/// to depend on results from earlier ones.
16///
17/// # Example JSON Definition
18///
19/// ```json
20/// {
21/// "id": "validate_user",
22/// "name": "Validate User Data",
23/// "description": "Ensures user data meets requirements",
24/// "condition": {"==": [{"var": "metadata.type"}, "user"]},
25/// "function": {
26/// "name": "validation",
27/// "input": { "rules": [...] }
28/// },
29/// "continue_on_error": false
30/// }
31/// ```
32#[derive(Clone, Debug, Deserialize)]
33pub struct Task {
34 /// Unique identifier for the task within the workflow.
35 pub id: String,
36
37 /// Human-readable name for the task.
38 pub name: String,
39
40 /// Optional description explaining what the task does.
41 pub description: Option<String>,
42
43 /// JSONLogic condition that determines if the task should execute.
44 /// Conditions can only access `metadata` fields, not `data` fields.
45 /// Defaults to `true` (always execute).
46 #[serde(default = "default_condition")]
47 pub condition: Value,
48
49 /// Index into the compiled logic cache for this task's condition.
50 /// Set during workflow compilation; not serialized.
51 #[serde(skip)]
52 pub condition_index: Option<usize>,
53
54 /// The function configuration specifying what operation to perform.
55 /// Can be a built-in function (map, validation) or a custom function.
56 pub function: FunctionConfig,
57
58 /// Whether to continue workflow execution if this task fails.
59 /// When `true`, errors are recorded but don't stop the workflow.
60 /// Defaults to `false`.
61 #[serde(default)]
62 pub continue_on_error: bool,
63}
64
65/// Returns the default condition value (always true).
66fn default_condition() -> Value {
67 Value::Bool(true)
68}