cloacina_macros/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 Macros
18//!
19//! This crate provides procedural macros for defining tasks and workflows in the Cloacina framework.
20//! It enables compile-time validation of task dependencies and workflow structure.
21//!
22//! ## Key Features
23//!
24//! - `#[task]` attribute macro for defining tasks with retry policies and trigger rules
25//! - `workflow!` macro for declarative workflow definition
26//! - `#[packaged_workflow]` attribute macro for creating distributable workflow packages
27//! - Compile-time validation of task dependencies and workflow structure
28//! - Automatic task and workflow registration
29//! - Code fingerprinting for task versioning
30//!
31//! ## Example
32//!
33//! ```rust
34//! use cloacina_macros::task;
35//!
36//! #[task(
37//! id = "my_task",
38//! dependencies = ["other_task"],
39//! retry_attempts = 3,
40//! retry_backoff = "exponential"
41//! )]
42//! async fn my_task(context: &mut Context<Value>) -> Result<(), TaskError> {
43//! // Task implementation
44//! Ok(())
45//! }
46//!
47//! use cloacina_macros::workflow;
48//!
49//! let workflow = workflow! {
50//! name: "my_workflow",
51//! description: "A sample workflow",
52//! tasks: [my_task, other_task]
53//! };
54//! ```
55
56mod packaged_workflow;
57mod registry;
58mod tasks;
59mod workflow;
60
61use proc_macro::TokenStream;
62
63#[proc_macro_attribute]
64pub fn task(args: TokenStream, input: TokenStream) -> TokenStream {
65 tasks::task(args, input)
66}
67
68#[proc_macro]
69pub fn workflow(input: TokenStream) -> TokenStream {
70 workflow::workflow(input)
71}
72
73#[proc_macro_attribute]
74pub fn packaged_workflow(args: TokenStream, input: TokenStream) -> TokenStream {
75 packaged_workflow::packaged_workflow(args, input)
76}