Skip to content

leo91000/graphile_worker_rs

Graphile Worker RS

Codecov Crates.io Documentation MIT License

A PostgreSQL-backed job queue for Rust applications, based on Graphile Worker.

Graphile Worker RS lets you run durable background jobs from Rust while keeping PostgreSQL as the queue and coordination backend. It supports typed task handlers, delayed jobs, priorities, queues, retries, cron jobs, graceful shutdown, optional dead-worker recovery, lifecycle hooks, CLI tooling, and an admin UI.

Documentation

  • Guide - task-oriented documentation, examples, configuration, operations, and troubleshooting.
  • API reference - generated Rust API docs.
  • Examples - runnable repository examples.

Installation

cargo add graphile_worker

Tokio, rustls, and SQLx are enabled by default:

[dependencies]
graphile_worker = "0.13"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde = { version = "1", features = ["derive"] }

For async-std, tokio-postgres, native TLS, or OpenTelemetry compatibility features, see the feature flags guide.

Quick Start

use graphile_worker::{
    IntoTaskHandlerResult, JobSpec, TaskHandler, WorkerContext, WorkerOptions,
};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
struct SendEmail {
    to: String,
}

impl TaskHandler for SendEmail {
    const IDENTIFIER: &'static str = "send_email";

    async fn run(self, _ctx: WorkerContext) -> impl IntoTaskHandlerResult {
        println!("Sending email to {}", self.to);
        Ok::<(), String>(())
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let worker = WorkerOptions::default()
        .database_url("postgres://postgres:password@localhost/mydb")
        .concurrency(5)
        .schema("graphile_worker")
        .define_job::<SendEmail>()
        .init()
        .await?;

    worker
        .create_utils()
        .add_job(
            SendEmail {
                to: "user@example.com".to_string(),
            },
            JobSpec::default(),
        )
        .await?;

    worker.run().await?;
    Ok(())
}

For a complete walkthrough, read Quick Start and First Worker.

Highlights

  • PostgreSQL-backed durable queue with SKIP LOCKED job claiming.
  • Low-latency wakeups through PostgreSQL LISTEN/NOTIFY.
  • Typed Rust task handlers and batch task handlers.
  • Delayed jobs, priorities, retry attempts, job keys, and named queues.
  • Cron-like recurring jobs through the crontab crates.
  • Worker utilities for adding, rescheduling, completing, failing, cleaning up, and recovering jobs.
  • Optional local queue for batch-fetching jobs and reducing database round trips.
  • Graceful shutdown and optional heartbeat-based dead-worker recovery.
  • Lifecycle hooks for logging, metrics, validation, and custom policies.
  • CLI and admin UI crates for operational workflows.

Compatibility

This is a Rust rewrite of Graphile Worker. It is mostly compatible with the Node.js version and can run side by side with it when the shared PostgreSQL schema and job contracts match.

One notable implementation difference: the Node.js version uses one worker id per process, while this Rust implementation uses one worker id per worker instance and processes jobs through the enabled async runtime.

See Compatibility for details.

Development

Common commands:

just lint
just test-docker
just docs
just docs-serve 3002

Before committing, run:

just lint
just test-docker

See CONTRIBUTING.md for contribution details.

License

MIT. See LICENSE.md.

About

High performance Rust/PostgreSQL job queue (also suitable for getting jobs generated by PostgreSQL triggers/functions out into a different work queue)

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors