Skip to main content

Crate kojin

Crate kojin 

Source
Expand description

§kojin

Async distributed task queue for Rust — the equivalent of Celery (Python), BullMQ (Node.js), Sidekiq (Ruby), and Machinery (Go).

This is the main facade crate. It re-exports types from kojin_core, the #[task] proc-macro from kojin_macros, and optionally the Redis broker from kojin_redis.

§Features

  • Async-first worker runtime built on Tokio
  • #[kojin::task] proc-macro for defining tasks
  • Pluggable broker trait (Redis included)
  • Composable middleware (tracing, metrics)
  • Workflow orchestration: chain, group, chord
  • Result backends (memory, Redis, PostgreSQL)
  • Graceful shutdown, weighted queues, configurable retries

§Quick Start

use kojin::{KojinBuilder, MemoryBroker};

let broker = MemoryBroker::new();
let worker = KojinBuilder::new(broker)
    .concurrency(4)
    .queues(vec!["default".into()])
    .build();
worker.run().await;

Modules§

backoff
broker
canvas
codec
context
error
memory_broker
memory_result_backend
message
middleware
queue_weight
registry
result_backend
shutdown
signature
state
task
task_id
worker

Macros§

chain
Create a chain of tasks.
group
Create a group of tasks.

Structs§

JsonCodec
JSON codec using serde_json.
KojinBuilder
Builder for configuring and running a Kojin worker.
MemoryBroker
In-memory broker for testing and development.
MemoryResultBackend
In-memory result backend for development and testing.
MetricsMiddleware
Simple metrics middleware that tracks task counts.
RedisBroker
Redis-backed message broker.
RedisConfig
Redis broker configuration.
RedisResultBackend
Redis-backed result storage.
Signature
A type-erased task invocation descriptor.
TaskContext
Task execution context providing type-safe access to shared data.
TaskId
Unique task identifier backed by UUID v7 (time-ordered).
TaskMessage
A task message that flows through the broker.
TaskRegistry
Registry mapping task names to type-erased handlers.
TracingMiddleware
Middleware that emits tracing spans for task execution.
WeightedQueue
A queue with an associated weight.
Worker
The worker loop that dequeues and executes tasks.
WorkerConfig
Worker configuration.
WorkflowHandle
Handle returned after submitting a workflow.

Enums§

BackoffStrategy
Strategy for calculating retry backoff delays.
Canvas
A composable workflow description.
KojinError
Core error type for Kojin.
QueueWeight
Queue priority weight for weighted queue selection.
TaskState
Lifecycle state of a task.

Traits§

Broker
Message broker responsible for enqueuing and dequeuing task messages.
Codec
Serialization codec for task payloads.
Middleware
Middleware hook for task execution pipeline.
ResultBackend
Backend for storing and retrieving task results.
Task
A unit of work that can be enqueued and executed by a worker.

Functions§

chord
Create a chord: a group with a callback that fires when all members complete.

Type Aliases§

TaskResult
Convenience result alias.

Attribute Macros§

task
Derive a task struct and Task impl from an async function.