celers 0.2.0

Celery-compatible distributed task queue for Rust (Facade crate)
Documentation
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# celers TODO

> Facade crate providing unified API for CeleRS

## Status: ✅ STABLE — v0.2.0 (2026-03-27) — 145 tests

All core features implemented and production-ready.

## Completed Features

### Core Exports ✅
- [x] Re-export core types (Broker, SerializedTask, TaskState)
- [x] Re-export protocol types (Message, MessageHeaders, etc.)
- [x] Re-export kombu types (Producer, Consumer, Transport, utils)
- [x] Re-export worker types (Worker, WorkerConfig)
- [x] Re-export canvas types (Chain, Chord, Group, Map, Starmap)
- [x] Re-export macros (task, Task derive)
- [x] Re-export broker utilities (monitoring, utilities for AMQP)
- [x] Re-export backend utilities (ttl, batch_size for Redis)

### Feature Flags ✅
- [x] Redis broker feature
- [x] PostgreSQL broker feature
- [x] MySQL broker feature
- [x] AMQP broker feature
- [x] SQS broker feature
- [x] Backend-redis feature
- [x] Metrics feature
- [x] Workflows feature
- [x] Beat feature

### Convenience Modules ✅
- [x] Prelude module for common imports
- [x] Error module for error types
- [x] Protocol module for advanced usage
- [x] Canvas module for workflows
- [x] Worker module for runtime

## Future Enhancements

### Additional Features
- [x] AMQP broker feature ✅
- [x] SQS broker feature ✅
- [x] MySQL broker feature ✅
- [x] Backend-db feature ✅
- [x] Backend-rpc feature ✅
- [x] Tracing feature (OpenTelemetry) ✅
  - [x] Full tracing integration ✅
  - [x] Span propagation ✅
  - [x] Trace context management ✅
- [ ] Additional broker features
  - [ ] Kafka broker feature
  - [ ] NATS broker feature
  - [ ] Azure Service Bus feature
  - [ ] Google Pub/Sub feature
- [ ] Additional backend features
  - [ ] S3 backend feature
  - [ ] Cassandra backend feature
  - [ ] MongoDB backend feature

### Documentation
- [x] Comprehensive README
- [x] Module-level documentation ✅
- [x] Examples in documentation ✅
- [x] Tutorial/getting started guide ✅
  - [x] Installation and setup ✅
  - [x] First task example ✅
  - [x] Worker configuration ✅
  - [x] Feature selection guide ✅
  - [x] Configuration examples ✅
  - [x] Testing guide ✅
  - [x] Production deployment ✅
    - [x] Infrastructure setup (Redis, PostgreSQL) ✅
    - [x] Worker configuration ✅
    - [x] Systemd service setup ✅
    - [x] Monitoring and observability ✅
    - [x] Performance tuning ✅
    - [x] High availability setup ✅
    - [x] Security best practices ✅
    - [x] Scaling strategies (Kubernetes) ✅
    - [x] Troubleshooting guide ✅
- [x] Migration guide from Python Celery ✅
  - [x] Feature comparison ✅
  - [x] API mapping ✅
  - [x] Code conversion examples ✅
  - [x] Performance differences ✅
  - [x] Migration checklist ✅
  - [x] Compatibility notes ✅
- [x] Architecture documentation ✅
  - [x] System design overview ✅
  - [x] Component interactions ✅
  - [x] Data flow diagrams ✅
  - [x] Scalability patterns ✅
- [x] Advanced guides ✅
  - [x] Performance tuning ✅
  - [x] Security best practices ✅
  - [x] Troubleshooting guide ✅
  - [x] Monitoring and alerting ✅

### Examples
- [x] Complete end-to-end example ✅
  - [x] Web application integration ✅
  - [x] Database tasks ✅
  - [x] Email sending ✅
  - [x] File processing (image processing) ✅
  - [x] Report generation ✅
  - [x] User registration workflow ✅
  - [x] Background cleanup tasks ✅
- [x] High-throughput processing example ✅
  - [x] Batch processing ✅
  - [x] Stream processing ✅
  - [x] Real-time analytics ✅
  - [x] ETL processes ✅
  - [x] Performance benchmarking ✅
- [x] Microservices example ✅
  - [x] Service-to-service communication ✅
  - [x] Event-driven architecture ✅
  - [x] Saga pattern implementation ✅
  - [x] Choreography pattern ✅
  - [x] Compensating transactions ✅
- [x] Distributed workflow example ✅
  - [x] Complex DAG workflows ✅
  - [x] Data pipeline (ETL) ✅
  - [x] Map-Reduce pattern ✅
  - [x] Multi-stage processing ✅
- [x] Additional real-world use cases ✅
  - [x] Video transcoding ✅
  - [x] Web scraping ✅
  - [x] Notification system ✅
  - [x] Multi-channel notifications ✅
  - [x] Video processing pipeline ✅

### Quality of Life
- [x] Builder pattern for Worker configuration ✅
  - [x] Fluent API
  - [x] Validation on build
  - [x] Preset configurations
- [x] Default broker selection helper ✅
  - [x] Auto-detect from environment (CELERS_BROKER_TYPE, CELERS_BROKER_URL, CELERS_BROKER_QUEUE)
  - [x] Explicit broker creation (create_broker function)
  - [x] Feature-aware error messages
  - [x] Support for all broker types (Redis, PostgreSQL, MySQL, AMQP, SQS)
- [x] Configuration validation ✅
  - [x] Schema validation ✅
  - [x] Runtime checks ✅
  - [x] Configuration preview ✅
- [x] Feature compatibility matrix ✅
  - [x] Document feature combinations ✅
  - [x] Warn on incompatibilities ✅
  - [x] Suggest alternatives ✅
- [x] Error messages and diagnostics ✅
  - [x] Helpful error messages ✅
  - [x] Suggestions for fixes ✅
  - [x] Context-aware errors ✅
- [x] Development utilities ✅
  - [x] Task testing helpers ✅
  - [x] Mock brokers for testing ✅
  - [x] Debugging tools ✅
    - [x] TaskDebugger for task inspection ✅
    - [x] EventTracker for event logging ✅
    - [x] PerformanceProfiler for execution time tracking ✅
    - [x] QueueInspector for queue state monitoring ✅

### Performance
- [x] Compile-time feature validation ✅
  - [x] Feature conflict detection ✅
  - [x] const fn validation ✅
  - [x] Feature summary reporting ✅
- [x] Performance benchmarks ✅
  - [x] Task creation benchmarks ✅
  - [x] Serialization benchmarks ✅
  - [x] Broker operation benchmarks ✅
  - [x] Workflow construction benchmarks ✅
  - [x] Throughput benchmarks ✅
  - [x] Memory usage benchmarks ✅
- [x] Zero-cost abstractions verification ✅
  - [x] Task creation overhead tests ✅
  - [x] Workflow construction overhead tests ✅
  - [x] Feature validation overhead tests ✅
  - [x] Memory efficiency tests ✅
  - [x] Inline optimization verification ✅
  - [x] Assembly inspection ✅
    - Added `assembly_inspection` module with utilities
    - Documentation for using cargo-asm, rustc, and Godbolt
    - Helper functions: `generate_asm`, `verify_inlined`, `count_instructions`, `compare_debug_release`
    - Guide on what to look for in assembly (inlining, dead code elimination, iterator optimization)
  - [x] Performance regression tests ✅
    - [x] Task creation regression test ✅
    - [x] Workflow construction regression test ✅
    - [x] Serialization regression test ✅
    - [x] Config validation regression test ✅
- [x] Bundle size optimization ✅
  - [x] Feature-specific builds ✅
  - [x] Link-time optimization ✅
  - [x] Binary size reporting (via profiles) ✅
  - [x] Multiple optimization profiles (release, release-small, release-fast) ✅
- [x] Startup time optimization ✅
  - [x] Lazy initialization (LazyInit helper) ✅
  - [x] Parallel initialization (parallel_init helper) ✅
  - [x] Pre-compiled regex/parsers (cached_regex) ✅
  - [x] Startup metrics tracking ✅
  - [x] time_init! macro for timing ✅

### Developer Experience
- [x] IDE support improvements ✅
  - [x] Better type hints (ide_support module) ✅
  - [x] Code completion (type aliases and trait bounds) ✅
  - [x] Inline documentation (quick_reference module) ✅
  - [x] Default constants (ide_support::defaults) ✅
  - [x] Example URLs (ide_support::examples) ✅
  - [x] Common patterns documentation ✅
  - [x] Troubleshooting guide ✅
- [ ] Procedural macro enhancements (in celers-macros crate)
  - [ ] Better error messages
  - [ ] More derive options
  - [ ] Custom attributes
- [x] Prelude improvements ✅
  - [x] More convenient imports (WorkerConfigBuilder, TaskState, Starmap, TaskOptions, BrokerError, Beat types)
  - [x] Context-aware re-exports ✅
    - [x] Convenience functions module (task, chain, group, chord) ✅
    - [x] Quick start helpers (redis_broker, postgres_broker, worker configs) ✅
    - [x] Production-ready presets (production_config, high_throughput_config, etc.) ✅
    - [x] Type aliases for common patterns (TaskResult, AsyncTaskFn) ✅
    - [x] Development utilities re-exported in prelude ✅

## Testing

- [x] Basic facade exports test ✅
- [x] Feature flag compatibility tests ✅
- [x] Configuration validation tests ✅
- [x] Mock broker tests ✅
- [x] Prelude imports test ✅
- [x] Integration tests with all brokers ✅
  - [x] Redis broker integration test ✅
  - [x] PostgreSQL broker integration test ✅
  - [x] MySQL broker integration test ✅
  - [x] AMQP broker integration test ✅
  - [x] SQS broker integration test ✅
  - [x] Redis backend integration test ✅
  - [x] Database backend integration tests ✅
  - [x] Beat scheduler integration test ✅
- [x] Workflow tests ✅
  - [x] Chain workflow test ✅
  - [x] Group workflow test ✅
  - [x] Chord workflow test ✅
- [x] Performance tests ✅
  - [x] Task creation performance test ✅
  - [x] Broker helper tests ✅
  - [x] Presets validation test ✅
  - [x] Compile-time validation test ✅
- [x] Zero-cost abstractions tests ✅
  - [x] Zero-cost task creation test ✅
  - [x] Zero-cost workflow construction test ✅
  - [x] Feature validation overhead test ✅
  - [x] Memory efficiency test ✅
  - [x] Inline optimization test ✅
- [x] Performance regression tests ✅
  - [x] Task creation regression test ✅
  - [x] Workflow construction regression test ✅
  - [x] Serialization regression test ✅
  - [x] Config validation regression test ✅
- [x] Startup optimization tests ✅
  - [x] LazyInit test ✅
  - [x] StartupMetrics test ✅
  - [x] Parallel initialization test ✅
- [x] IDE support tests ✅
  - [x] Type aliases test ✅
  - [x] Default constants test ✅
  - [x] Example URLs test ✅
  - [x] Trait bounds test ✅
  - [x] BoxedFuture test ✅
- [ ] Documentation tests (31 currently ignored - require actual broker connections)
- [x] Example code tests ✅
  - [x] Web application example ✅
  - [x] High-throughput example ✅
  - [x] Microservices example ✅
  - [x] Distributed workflow example ✅
  - [x] Real-world use cases example ✅

## Dependencies

All dependencies are re-exported from sub-crates.

## Notes

- This is a facade crate - implementation is in sub-crates
- Keep minimal code in this crate (just re-exports)
- All feature flags should pass through to sub-crates
- Documentation should link to sub-crate docs for details

## Recent Enhancements (2026-01-06 - Part 2)

### Advanced Task Management Utilities ✅
This enhancement session added four more comprehensive utility modules for advanced task management:

#### 1. Task Cancellation Utilities Module ✅
- **`task_cancellation`** module for task lifecycle control:
  - **`CancellationToken`**: Thread-safe cancellation token with reason tracking
  - **`TimeoutManager`**: Timeout tracking and enforcement
  - **`ExecutionGuard`**: Combined cancellation and timeout management
- Check and enforce cancellation during task execution
- Track remaining timeout and elapsed time
- Provide cancellation reasons for better debugging

#### 2. Advanced Retry Strategies Module ✅
- **`retry_strategies`** module for sophisticated retry patterns:
  - **`RetryStrategy`**: Configurable retry strategy with multiple algorithms
  - **`RetryPolicy`**: Trait for custom retry decision logic
  - **`DefaultRetryPolicy`**: Retry all errors up to max attempts
  - **`ErrorPatternRetryPolicy`**: Retry only specific error patterns
- Pre-configured retry strategies:
  - `exponential_backoff(max_retries, initial_delay)`: Exponential backoff with jitter
  - `linear_backoff(max_retries, delay)`: Linear delay increase
  - `fixed_delay(max_retries, delay)`: Constant delay
  - `fibonacci_backoff(max_retries, base_delay)`: Fibonacci sequence delays
- Jitter support (±25%) to prevent thundering herd
- Configurable max delay and backoff multiplier
- Error-aware retry decisions

#### 3. Task Dependency Management Module ✅
- **`task_dependencies`** module for workflow orchestration:
  - **`DependencyGraph`**: Build and manage task dependency graphs
- Dependency tracking and validation:
  - Add tasks and dependencies
  - Get direct dependencies and dependents
  - Circular dependency detection
  - Topological sort for execution order
  - Get ready tasks (all dependencies satisfied)
- Essential for complex workflow orchestration
- Prevents circular dependency issues
- Ensures correct task execution order

#### 4. Performance Profiling Utilities Module ✅
- **`performance_profiling`** module for execution analysis:
  - **`PerformanceProfile`**: Detailed performance metrics per operation
  - **`PerformanceProfiler`**: Track and analyze task execution
  - **`ProfileSpan<'a>`**: RAII guard for automatic span tracking
- Comprehensive profiling features:
  - Track total duration, self time, children time
  - Multiple invocation tracking and averaging
  - Percentile calculations for latency distribution
  - Identify slowest operations
  - Generate performance reports
- Thread-safe profiling with Arc/Mutex
- Hierarchical span tracking

### Test Coverage ✅
- Added 14 new comprehensive unit tests:
  - 3 tests for task cancellation utilities
  - 4 tests for retry strategies
  - 4 tests for task dependencies
  - 4 tests for performance profiling
  - 1 test for prelude exports verification
- Total tests increased from 103 to 117 unit tests (14% increase)
- All tests pass with 100% success rate
- Zero warnings in all builds

### Build Quality ✅
- Zero build warnings
- Zero clippy warnings
- All 117 unit tests passing (up from 103)
- All 8 doc tests passing
- Clean builds in both debug and release modes
- NO WARNINGS POLICY maintained

### Dependencies ✅
- Added `rand = "0.8"` for retry jitter functionality

### Prelude Integration ✅
All new types exported in prelude for easy access:
- `CancellationToken`, `TimeoutManager`, `ExecutionGuard`
- `RetryStrategy`, `DefaultRetryPolicy`, `ErrorPatternRetryPolicy`, `RetryPolicy` trait
- `DependencyGraph`
- `PerformanceProfile`, `ProfileSpan` (PerformanceProfiler accessed via module to avoid conflict)

### Summary of 2026-01-06 Part 2 Enhancements ✅
This enhancement session added:
- **4 new comprehensive modules** (task_cancellation, retry_strategies, task_dependencies, performance_profiling)
- **15+ new public API types and functions** for advanced task management
- **14 new comprehensive unit tests** with 100% pass rate
- **Total: 15+ new public API items** improving task control and observability
- All changes maintain backward compatibility
- Zero warnings policy maintained across all builds
- Documentation fully updated for all new features
- Better task lifecycle management, dependency tracking, and performance analysis

## Recent Enhancements (2026-01-06 - Part 1)

### Advanced Production Utilities ✅
This enhancement session added four comprehensive utility modules for production workloads:

#### 1. Health Check Utilities Module ✅
- **`health_check`** module with comprehensive health monitoring:
  - **`HealthStatus`**: Health status enum (Healthy, Degraded, Unhealthy)
  - **`HealthCheckResult`**: Health check result with metadata builder
  - **`WorkerHealthChecker`**: Worker health monitoring with heartbeat and task tracking
  - **`DependencyChecker`**: External dependency health checking
- Supports readiness, liveness, and dependency checks
- Configurable timeouts and metadata tracking
- Default 30s heartbeat timeout, 5min task timeout

#### 2. Resource Management Module ✅
- **`resource_management`** module for resource control:
  - **`ResourceLimits`**: Resource limit configuration (memory, CPU, time, file descriptors)
  - **`ResourceTracker`**: Track and enforce resource usage
  - **`ResourcePool<T>`**: Generic resource pooling
- Pre-configured limit presets:
  - `unlimited()`: No restrictions
  - `memory_constrained(mb)`: Memory-limited tasks
  - `cpu_intensive(seconds)`: CPU-bound tasks
  - `io_intensive(seconds)`: I/O-bound tasks
- Fluent API for custom limit configuration
- Thread-safe resource tracking with Arc/Mutex

#### 3. Task Lifecycle Hooks Module ✅
- **`task_hooks`** module for task execution hooks:
  - **`PreExecutionHook`**: Trait for pre-execution hooks
  - **`PostExecutionHook`**: Trait for post-execution hooks
  - **`HookRegistry`**: Manage and execute multiple hooks
  - **`LoggingHook`**: Built-in logging hook
  - **`ValidationHook<F>`**: Generic validation hook
- Hooks can modify arguments, abort execution, or track metrics
- Support for multiple hooks per lifecycle event
- Type-safe hook execution with error handling

#### 4. Metrics Aggregation Module ✅
- **`metrics_aggregation`** module for advanced metrics:
  - **`Histogram`**: Value distribution tracking with percentiles
  - **`MetricsAggregator`**: Comprehensive task metrics collection
  - **`DataPoint`**: Time-series data point
- Tracks execution counts, durations, errors, and success rates
- Percentile calculations (P50, P95, P99)
- Throughput measurement (tasks/sec)
- Summary report generation
- Time-series data collection for trend analysis

### Test Coverage ✅
- Added 14 new comprehensive unit tests:
  - 3 tests for health check utilities
  - 3 tests for resource management
  - 4 tests for task lifecycle hooks
  - 5 tests for metrics aggregation
  - 1 test for prelude exports verification
- Total tests increased from 89 to 103 unit tests (16% increase)
- All tests pass with 100% success rate
- Zero warnings in all builds

### Build Quality ✅
- Zero build warnings
- Zero clippy warnings (auto-fixed 2 or_insert_with warnings)
- All 103 unit tests passing (up from 89)
- All 8 doc tests passing
- Clean builds in both debug and release modes
- NO WARNINGS POLICY maintained

### Prelude Integration ✅
All new types exported in prelude for easy access:
- `WorkerHealthChecker`, `DependencyChecker`, `HealthCheckResult`, `HealthStatus`
- `ResourceLimits`, `ResourceTracker`, `ResourcePool<T>`
- `HookRegistry`, `PreExecutionHook`, `PostExecutionHook`, `LoggingHook`, `ValidationHook<F>`
- `MetricsAggregator`, `Histogram`, `DataPoint`

### Summary of 2026-01-06 Enhancements ✅
This enhancement session added:
- **4 new comprehensive modules** (health_check, resource_management, task_hooks, metrics_aggregation)
- **20+ new public API types and functions** for production operations
- **14 new comprehensive unit tests** with 100% pass rate
- **Total: 20+ new public API items** improving production-readiness
- All changes maintain backward compatibility
- Zero warnings policy maintained across all builds
- Documentation fully updated for all new features
- Better production monitoring, resource control, and observability