celers-core
Core abstractions and traits for the CeleRS distributed task queue system.
Status: [Stable] — v0.3.0 (2026-07-13) — 438 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:
DistributedLockBackendtrait (implementations live downstream:InMemoryLockBackendin celers-beat,RedisLockBackendin celers-backend-redis,DbLockBackendin celers-backend-db) - DAG support: Task dependency graphs with cycle detection
- Local development mode:
InMemoryBroker/InMemoryResultBackend(full trait coverage, no external services) plus aCachingResultBackend<B>LRU wrapper fronting anyResultStore - Distributed rate limiting:
DistributedRateLimiter+DistributedRateLimitBackendtrait (Redis-ready),TenantRateLimiterfor per-tenant quotas, andTaskTypeCircuitBreakersfor per-task-type circuit breaking - Result lifecycle: tombstones (
TombstoneRegistry/ResultExistence), result groups (ResultGroup), and per-task-type result TTL (ResultTtlConfig) - Alerting: event snapshots (
EventSnapshot) and a rule engine (AlertRule/AlertEvaluator) for failure-rate, queue-depth, and no-heartbeat alerts - Task security: HMAC-SHA256 task signing (
TaskSigner), argument sanitization (Sanitizer), and PII detection/masking (PiiDetector)
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 ;
// Implement `Task` for your task type (register() takes a value, not a closure)
;
let registry = new;
// Register by value — the task name comes from `Task::name()`
registry.register.await;
// 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", = ["derive"] }
= "1"
= "2"
= { = "1", = ["full"] }
= { = "1", = ["v4", "serde"] }
= { = "0.4", = ["serde"] }
= "0.1"
= "1"
= "0.10"
= "1"
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