Skip to main content

cloacina_workflow/
lib.rs

1/*
2 *  Copyright 2025 Colliery Software
3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 *  you may not use this file except in compliance with the License.
6 *  You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *  Unless required by applicable law or agreed to in writing, software
11 *  distributed under the License is distributed on an "AS IS" BASIS,
12 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *  See the License for the specific language governing permissions and
14 *  limitations under the License.
15 */
16
17//! # Cloacina Workflow - Minimal Types for Workflow Authoring
18//!
19//! This crate provides the minimal set of types needed to compile Cloacina workflows
20//! without pulling in heavy runtime dependencies like database drivers.
21//!
22//! ## Purpose
23//!
24//! Workflow authors who only need to compile workflows can depend on this lightweight
25//! crate instead of the full `cloacina` crate. This provides:
26//!
27//! - Faster compile times
28//! - Smaller binary sizes
29//! - Easier cross-compilation (no native database drivers)
30//! - Clear separation between "authoring workflows" and "running workflows"
31//!
32//! ## Types Provided
33//!
34//! - [`Context`] - Data container for sharing values between tasks
35//! - [`Task`] - Trait defining executable tasks
36//! - [`TaskState`] - Task execution state enum
37//! - [`TaskNamespace`] - Hierarchical task identification
38//! - [`TaskError`], [`ContextError`], [`CheckpointError`] - Error types
39//! - [`RetryPolicy`], [`BackoffStrategy`], [`RetryCondition`] - Retry configuration
40//!
41//! ## Usage
42//!
43//! ```rust
44//! use cloacina_workflow::{Context, TaskError};
45//!
46//! // Create a context
47//! let mut ctx = Context::<serde_json::Value>::new();
48//! ctx.insert("key", serde_json::json!("value")).unwrap();
49//!
50//! // Access data
51//! let value = ctx.get("key").unwrap();
52//! ```
53//!
54//! ## With the Task Macro
55//!
56//! The macros are included by default, so you only need one import:
57//!
58//! ```rust,ignore
59//! use cloacina_workflow::{task, packaged_workflow, Context, TaskError};
60//!
61//! #[task(id = "my_task", dependencies = [])]
62//! async fn my_task(ctx: &mut Context<serde_json::Value>) -> Result<(), TaskError> {
63//!     ctx.insert("result", serde_json::json!("done"))?;
64//!     Ok(())
65//! }
66//! ```
67
68pub mod context;
69pub mod error;
70pub mod namespace;
71pub mod retry;
72pub mod task;
73
74// Re-export primary types at crate root for convenience
75pub use context::Context;
76pub use error::{CheckpointError, ContextError, TaskError};
77pub use namespace::{parse_namespace, TaskNamespace};
78pub use retry::{BackoffStrategy, RetryCondition, RetryPolicy, RetryPolicyBuilder};
79pub use task::{Task, TaskState};
80
81// Re-export macros when the feature is enabled
82#[cfg(feature = "macros")]
83pub use cloacina_macros::{packaged_workflow, task, workflow};