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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
use crate;
use crateSignature;
use Value;
/// Creates an ETL (Extract, Transform, Load) pipeline workflow
///
/// This pattern is commonly used for data processing pipelines where data
/// flows through multiple transformation stages.
///
/// # Arguments
///
/// * `extract_task` - Name of the task that extracts data
/// * `extract_args` - Arguments for the extract task
/// * `transform_task` - Name of the task that transforms data
/// * `load_task` - Name of the task that loads processed data
///
/// # Example
///
/// ```rust,ignore
/// use celers::workflow_templates::etl_pipeline;
/// use serde_json::json;
///
/// let pipeline = etl_pipeline(
/// "extract_from_api",
/// vec![json!({"url": "https://api.example.com"})],
/// "transform_data",
/// "load_to_database"
/// );
///
/// pipeline.apply_async(&broker).await?;
/// ```
/// Creates a Map-Reduce workflow for parallel processing with aggregation
///
/// This pattern processes items in parallel (map phase) and then aggregates
/// the results (reduce phase).
///
/// # Arguments
///
/// * `map_task` - Name of the task to apply to each item
/// * `items` - Collection of items to process
/// * `reduce_task` - Name of the task that aggregates results
///
/// # Example
///
/// ```rust,ignore
/// use celers::workflow_templates::map_reduce_workflow;
/// use serde_json::json;
///
/// let workflow = map_reduce_workflow(
/// "process_number",
/// vec![json!(1), json!(2), json!(3), json!(4)],
/// "sum_results"
/// );
/// ```
/// Creates a scatter-gather workflow for distributing work
///
/// This pattern distributes different tasks to be executed in parallel
/// and then gathers all results.
///
/// # Arguments
///
/// * `tasks` - List of (task_name, args) tuples to execute in parallel
/// * `gather_task` - Name of the task that gathers all results
///
/// # Example
///
/// ```rust,ignore
/// use celers::workflow_templates::scatter_gather;
/// use serde_json::json;
///
/// let tasks = vec![
/// ("fetch_user_data", vec![json!({"user_id": 1})]),
/// ("fetch_order_data", vec![json!({"user_id": 1})]),
/// ("fetch_preferences", vec![json!({"user_id": 1})]),
/// ];
///
/// let workflow = scatter_gather(tasks, "combine_user_profile");
/// ```
/// Creates a batch processing workflow with automatic chunking
///
/// This pattern processes large datasets by dividing them into batches,
/// processing each batch in parallel, and then aggregating results.
///
/// # Arguments
///
/// * `process_task` - Name of the task that processes a batch
/// * `items` - All items to process
/// * `batch_size` - Number of items per batch
/// * `aggregate_task` - Optional task to aggregate all batch results
///
/// # Example
///
/// ```rust,ignore
/// use celers::workflow_templates::batch_processing;
/// use serde_json::json;
///
/// let items = (1..=100).map(|i| json!(i)).collect();
/// let workflow = batch_processing(
/// "process_batch",
/// items,
/// 10, // Process 10 items per batch
/// Some("combine_batch_results")
/// );
/// ```
/// Creates a sequential pipeline workflow with error handling
///
/// This pattern chains tasks sequentially with automatic retry and
/// error recovery built in.
///
/// # Arguments
///
/// * `stages` - List of (task_name, args, max_retries) tuples
///
/// # Example
///
/// ```rust,ignore
/// use celers::workflow_templates::sequential_pipeline;
/// use serde_json::json;
///
/// let stages = vec![
/// ("validate_input", vec![json!({"data": "test"})], 3),
/// ("process_data", vec![], 5),
/// ("save_results", vec![], 3),
/// ];
///
/// let pipeline = sequential_pipeline(stages);
/// ```
/// Creates a priority-based workflow for handling urgent tasks first
///
/// This pattern creates parallel tasks with different priorities,
/// ensuring high-priority tasks are processed first.
///
/// # Arguments
///
/// * `tasks` - List of (task_name, args, priority) tuples
///
/// # Example
///
/// ```rust,ignore
/// use celers::workflow_templates::priority_workflow;
/// use serde_json::json;
///
/// let tasks = vec![
/// ("critical_task", vec![json!(1)], 9),
/// ("normal_task", vec![json!(2)], 5),
/// ("low_priority_task", vec![json!(3)], 1),
/// ];
///
/// let workflow = priority_workflow(tasks);
/// ```