kojin
Async distributed task queue for Rust — the equivalent of Celery / Dramatiq (Python), BullMQ (Node.js), Sidekiq (Ruby), and Machinery (Go).
Features
- Async-first — built on Tokio, designed for
async/awaitfrom the ground up #[kojin::task]— proc-macro to define tasks from plain async functions- Pluggable broker — trait-based broker abstraction (Redis included, bring your own)
- Workflows — chain, group, chord orchestration with
chain![],group![]macros - Result backends — Memory, Redis, PostgreSQL for storing task results and coordinating workflows
- Cron scheduling — periodic task execution with standard cron expressions
- Middleware — composable pre/post-execution hooks (tracing, metrics, custom)
- Graceful shutdown — cooperative cancellation via
CancellationToken - Weighted queues — prioritize work across multiple queues
- Configurable retries — per-task retry limits with backoff strategies
Quick Start
Add to your Cargo.toml:
[]
= "0.2"
= { = "1", = ["full"] }
= { = "1", = ["derive"] }
= "0.1"
Define a task, enqueue it, and run a worker:
use async_trait;
use ;
use ;
async
Workflows
Kojin supports Celery-style workflow primitives — chain!, group!, and chord — for composing tasks into DAGs. A result backend is required.
use ;
// Signatures describe a task invocation (name, queue, payload)
let fetch = new;
let parse = new;
let store = new;
// Chain — sequential: fetch → parse → store
let pipeline = chain!;
// Group — parallel: fetch three URLs concurrently
let batch = group!;
// Chord — parallel + callback: fetch all, then aggregate
let aggregate = new;
let workflow = chord;
// Submit to the broker
let handle = pipeline.apply.await?;
See examples/workflow_demo.rs for a complete runnable example.
Cron Scheduling
With the cron feature flag, you can schedule periodic tasks using standard cron expressions:
[]
= { = "0.2", = ["cron"] }
use ;
let worker = new
.
.result_backend
.cron
.build;
worker.run.await;
See examples/cron_demo.rs for a complete runnable example.
Crate Architecture
| Crate | Description |
|---|---|
kojin |
Facade crate — re-exports everything, provides KojinBuilder |
kojin-core |
Core traits (Task, Broker, Middleware), worker runtime, workflows, types |
kojin-macros |
#[kojin::task] proc-macro |
kojin-redis |
Redis broker + result backend via deadpool-redis |
kojin-postgres |
PostgreSQL result backend via sqlx |
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.