celers-core
Core abstractions and traits for the CeleRS distributed task queue system.
Status: [Stable] — v0.2.0 (2026-03-27) — 247 tests
Overview
This crate provides the fundamental building blocks for CeleRS:
- Task trait: Type-safe executable task interface
- Broker trait: Abstract interface for message brokers (Redis, Postgres, AMQP, SQS, etc.)
- ResultBackend trait: Task result storage abstraction
- TaskExecutor / TaskRegistry: Task execution and registration
- Error types: Comprehensive error handling with retryability classification
- Batch operations: High-performance bulk enqueue/dequeue (10-100x faster)
- CeleryConfig: Full configuration with 23+ environment variables
- Router: Pattern-based task routing
- RateLimit, TimeLimit: Task rate and time limiting
- Revocation: Task cancellation and revocation
- Retry / Exception: Advanced retry strategies and exception policies
- Event / Control: Worker events and control commands
- Distributed Locks: DistributedLockBackend, InMemoryLockBackend, RedisLockBackend, DbLockBackend
- DAG support: Task dependency graphs with cycle detection
Features
- Type-safe task definitions
- Broker abstraction for multiple backends
- Task state machine (Pending → Running → Success/Failure/Retry)
- Batch operation support (10-100x performance improvement)
- Workflow support (Group, Chain, Chord)
- Async/await native
- Property-based testing coverage
Usage
use ;
// Create a task
let task = new;
// Enqueue to broker
let task_id = broker.enqueue.await?;
// Batch enqueue for better performance
let task_ids = broker.enqueue_batch.await?;
// Dequeue and execute
if let Some = broker.dequeue.await?
Broker Trait
The core abstraction for message brokers:
Task Types
SerializedTask
TaskMetadata
TaskState
Task Registry
Execute registered tasks by name:
use TaskRegistry;
let mut registry = new;
// Register a task executor
registry.register;
// Execute by name
let result = registry.execute.await?;
Error Handling
pub type Result<T> = Result;
Performance
Batch Operations
Batch operations provide significant performance improvements:
| Operation | Individual | Batch (10) | Batch (100) |
|---|---|---|---|
| Throughput | 1K/sec | 10K/sec | 50K/sec |
| Latency | 1ms/task | 0.1ms/task | 0.01ms/task |
| Network RTT | N | 1 | 1 |
Best Practices
// Good: Batch enqueue for bulk operations
let tasks = create_many_tasks;
broker.enqueue_batch.await?;
// Less efficient: Individual enqueue
for task in tasks
Workflow Support
TaskMetadata includes fields for Canvas workflow primitives:
// Group tasks
task.metadata.group_id = Some;
// Chord tasks (map-reduce)
task.metadata.chord_id = Some;
See celers-canvas for high-level workflow APIs.
Configuration
CeleryConfig supports 23+ environment variables including:
CELERY_BROKER_URL,CELERY_RESULT_BACKENDCELERY_TASK_SERIALIZER,CELERY_RESULT_SERIALIZERCELERY_TASK_DEFAULT_QUEUE,CELERY_TASK_ROUTESCELERY_WORKER_CONCURRENCY,CELERY_TASK_SOFT_TIME_LIMIT,CELERY_TASK_TIME_LIMIT- And more — use
CeleryConfig::from_env()orConfigValidation::validate_detailed()
Dependencies
[]
= "0.1"
= { = "1", = ["v4", "serde"] }
= { = "1", = ["derive"] }
= { = "0.4", = ["serde"] }
= "2"
= "1"
= "0.9"
See Also
- celers-broker-redis: Redis broker with batch operations
- celers-broker-postgres: PostgreSQL broker implementation
- celers-worker: Worker runtime for executing tasks
- celers-canvas: High-level workflow APIs (Chain, Group, Chord)
License
Apache-2.0