Skip to main content

Module docket

Module docket 

Source
Expand description

Docket: Distributed task queue for FastMCP.

Provides distributed task queue capabilities with support for multiple backends:

  • Memory: In-process queue for testing and development
  • Redis: Distributed queue for production deployments

§Architecture

┌────────────────────────────────────────────────────────────┐
│                        Docket                              │
│  ┌─────────────────┐  ┌─────────────────┐                  │
│  │   DocketClient  │  │   Worker Pool   │                  │
│  │   (task submit) │  │   (processing)  │                  │
│  └────────┬────────┘  └────────┬────────┘                  │
│           │                    │                           │
│           └──────────┬─────────┘                           │
│                      ▼                                     │
│           ┌────────────────────┐                           │
│           │   DocketBackend    │                           │
│           └─────────┬──────────┘                           │
│                     │                                      │
│       ┌─────────────┼─────────────┐                        │
│       ▼             ▼             ▼                        │
│  ┌─────────┐  ┌─────────┐  ┌─────────────┐                 │
│  │ Memory  │  │  Redis  │  │   Future    │                 │
│  │ Backend │  │ Backend │  │  Backends   │                 │
│  └─────────┘  └─────────┘  └─────────────┘                 │
└────────────────────────────────────────────────────────────┘

§Usage

use fastmcp_server::docket::{Docket, DocketSettings, Worker};

// Create with memory backend (testing/development)
let docket = Docket::memory();

// Create with Redis backend (production)
let settings = DocketSettings::redis("redis://localhost:6379");
let docket = Docket::new(settings)?;

// Submit a task
let task_id = docket.submit("process_data", json!({"input": "data"})).await?;

// Create a worker
let worker = docket.worker()
    .subscribe("process_data", |task| async move {
        // Process the task
        Ok(json!({"result": "processed"}))
    })
    .build();

// Start processing
worker.run().await?;

Structs§

Docket
Docket distributed task queue.
DocketSettings
Settings for configuring a Docket instance.
DocketTask
A queued task in the Docket system.
MemoryDocketBackend
In-memory Docket backend for testing and development.
QueueStats
Queue statistics.
RedisSettings
Redis connection settings.
SubmitOptions
Options for submitting a task.
Worker
A worker that processes tasks from the queue.
WorkerBuilder
Builder for creating workers.

Enums§

DocketBackendType
Backend type configuration.
DocketError
Errors that can occur in Docket operations.

Traits§

DocketBackend
Backend trait for Docket storage.

Type Aliases§

DocketResult
Result type for Docket operations.
SharedDocket
Thread-safe handle to a Docket.
TaskHandlerFn
Task handler function type.