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
use crate::;
use Value;
/// Creates a task chain with a fallback task in case of failure
///
/// This pattern provides a fallback mechanism where if the primary task fails,
/// a secondary fallback task is executed instead.
///
/// # Arguments
///
/// * `primary_task` - Name of the primary task to execute
/// * `primary_args` - Arguments for the primary task
/// * `fallback_task` - Name of the fallback task to execute on failure
/// * `fallback_args` - Arguments for the fallback task
///
/// # Example
///
/// ```rust,ignore
/// use celers::error_recovery::with_fallback;
/// use serde_json::json;
///
/// let task = with_fallback(
/// "fetch_from_primary_api",
/// vec![json!({"url": "https://api.example.com"})],
/// "fetch_from_backup_api",
/// vec![json!({"url": "https://backup.example.com"})]
/// );
/// ```
///
/// # Note
///
/// The actual fallback logic must be implemented in the task handlers.
/// This function creates the workflow structure.
/// Creates a task signature with error suppression
///
/// Configures a task to ignore errors and continue execution.
/// Useful for non-critical tasks where failures shouldn't block the workflow.
///
/// # Arguments
///
/// * `task_name` - Name of the task
/// * `args` - Task arguments
///
/// # Example
///
/// ```rust,ignore
/// use celers::error_recovery::ignore_errors;
/// use serde_json::json;
///
/// let sig = ignore_errors(
/// "log_analytics",
/// vec![json!({"event": "user_action"})]
/// );
/// ```
/// Creates a task with graduated retry delays
///
/// Implements exponential backoff retry strategy for tasks that may
/// experience transient failures.
///
/// # Arguments
///
/// * `task_name` - Name of the task
/// * `args` - Task arguments
/// * `max_retries` - Maximum number of retry attempts
/// * `base_delay` - Initial delay in seconds (doubles each retry)
///
/// # Example
///
/// ```rust,ignore
/// use celers::error_recovery::with_exponential_backoff;
/// use serde_json::json;
///
/// let sig = with_exponential_backoff(
/// "call_flaky_api",
/// vec![json!({"endpoint": "/data"})],
/// 5, // Retry up to 5 times
/// 2 // Start with 2 second delay, then 4, 8, 16, 32
/// );
/// ```
/// Creates a task with a dead letter queue on failure
///
/// Routes failed tasks to a designated error handling queue.
///
/// # Arguments
///
/// * `task_name` - Name of the task
/// * `args` - Task arguments
/// * `dlq_task` - Name of the dead letter queue handler task
///
/// # Example
///
/// ```rust,ignore
/// use celers::error_recovery::with_dlq;
/// use serde_json::json;
///
/// let task = with_dlq(
/// "process_payment",
/// vec![json!({"amount": 100})],
/// "handle_failed_payment"
/// );
/// ```