1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
use crate::;
use Value;
/// Creates a conditional workflow with success and failure branches
///
/// This creates a chain that includes both success and failure paths.
/// The actual branching logic must be implemented in the condition task.
///
/// # Arguments
///
/// * `condition_task` - Task that evaluates the condition
/// * `condition_args` - Arguments for the condition task
/// * `success_task` - Task to execute on success
/// * `success_args` - Arguments for success task
/// * `failure_task` - Task to execute on failure
/// * `failure_args` - Arguments for failure task
///
/// # Example
///
/// ```rust,ignore
/// use celers::advanced_patterns::create_conditional_workflow;
/// use serde_json::json;
///
/// let workflow = create_conditional_workflow(
/// "check_balance",
/// vec![json!({"account_id": 123})],
/// "process_payment",
/// vec![json!({"amount": 100})],
/// "send_insufficient_funds_notice",
/// vec![json!({"account_id": 123})]
/// );
/// ```
/// Creates a dynamic workflow where tasks are generated at runtime
///
/// This pattern allows for workflows where the number and type of tasks
/// are determined dynamically based on input data.
///
/// # Arguments
///
/// * `generator_task` - Task that generates the list of tasks to execute
/// * `generator_args` - Arguments for the generator task
/// * `executor_task` - Task that executes the generated tasks
///
/// # Example
///
/// ```rust,ignore
/// use celers::advanced_patterns::create_dynamic_workflow;
/// use serde_json::json;
///
/// let workflow = create_dynamic_workflow(
/// "generate_tasks",
/// vec![json!({"rules": "config.json"})],
/// "execute_task"
/// );
/// ```
/// Creates a workflow with parallel sub-chains
///
/// This pattern executes multiple chains in parallel, useful for
/// independent workflows that should run concurrently.
///
/// # Arguments
///
/// * `chains` - List of (chain_name, tasks) tuples
/// * `aggregate_task` - Optional task to aggregate results from all chains
///
/// # Example
///
/// ```rust,ignore
/// use celers::advanced_patterns::create_parallel_chains;
/// use serde_json::json;
///
/// let chains = vec![
/// ("process_images", vec![("resize", vec![]), ("optimize", vec![])]),
/// ("process_videos", vec![("transcode", vec![]), ("thumbnail", vec![])]),
/// ];
///
/// let workflow = create_parallel_chains(chains, Some("finalize"));
/// ```
/// Creates a saga pattern workflow for distributed transactions
///
/// Implements the saga pattern with compensating transactions for each step.
///
/// # Arguments
///
/// * `steps` - List of (forward_task, forward_args, compensate_task, compensate_args) tuples
///
/// # Example
///
/// ```rust,ignore
/// use celers::advanced_patterns::create_saga_workflow;
/// use serde_json::json;
///
/// let steps = vec![
/// ("reserve_inventory", vec![json!(1)], "release_inventory", vec![json!(1)]),
/// ("charge_payment", vec![json!(2)], "refund_payment", vec![json!(2)]),
/// ("ship_order", vec![json!(3)], "cancel_shipment", vec![json!(3)]),
/// ];
///
/// let workflow = create_saga_workflow(steps);
/// ```