#api-bindings #server-api #job-server #work-server

bin+lib faktory

API bindings for the language-agnostic Faktory work server

36 releases

0.12.5 Feb 18, 2024
0.12.1 Sep 17, 2022
0.12.0 May 28, 2022
0.11.1 Apr 27, 2021
0.8.8 Nov 14, 2017

#318 in Network programming

Download history 44/week @ 2024-01-24 46/week @ 2024-01-31 41/week @ 2024-02-07 265/week @ 2024-02-14 219/week @ 2024-02-21 117/week @ 2024-02-28 100/week @ 2024-03-06 79/week @ 2024-03-13 15/week @ 2024-03-20 38/week @ 2024-03-27 75/week @ 2024-04-03 82/week @ 2024-04-10 31/week @ 2024-04-17 50/week @ 2024-04-24 29/week @ 2024-05-01 8/week @ 2024-05-08

122 downloads per month


2.5K SLoC


Crates.io Documentation Codecov dependency status

API bindings for Faktory workers and job producers.

This crate provides API bindings for the language-agnostic Faktory work server. For a more detailed system overview of the work server, what jobs are, and how they are scheduled, see the Faktory docs.

System overview

At a high level, Faktory has two primary concepts: jobs and workers. Jobs are pieces of work that clients want to have executed, and workers are the things that eventually execute those jobs. A client enqueues a job, Faktory sends the job to an available worker (and waits if they're all busy), the worker executes the job, and eventually reports back to Faktory that the job has completed.

Jobs are self-contained, and consist of a job type (a string), arguments for the job, and bits and pieces of metadata. When a job is scheduled for execution, the worker is given this information, and uses the job type to figure out how to execute the job. You can think of job execution as a remote function call (or RPC) where the job type is the name of the function, and the job arguments are, perhaps unsuprisingly, the arguments to the function.

In this crate, you will find bindings both for submitting jobs (clients that produce jobs) and for executing jobs (workers that consume jobs). The former can be done by making a Producer, whereas the latter is done with a Consumer. See the documentation for each for more details on how to use them.

Encrypted connections (TLS)

To connect to a Faktory server hosted over TLS, add the tls feature, and see the documentation for TlsStream, which can be supplied to Producer::connect_with and Consumer::connect_with.


If you want to submit jobs to Faktory, use Producer.

use faktory::{Producer, Job};
let mut p = Producer::connect(None).unwrap();
p.enqueue(Job::new("foobar", vec!["z"])).unwrap();

If you want to accept jobs from Faktory, use Consumer.

use faktory::ConsumerBuilder;
use std::io;
let mut c = ConsumerBuilder::default();
c.register("foobar", |job| -> io::Result<()> {
    println!("{:?}", job);
let mut c = c.connect(None).unwrap();
if let Err(e) = c.run(&["default"]) {
    println!("worker failed: {}", e);

Run test suite locally

First ensure the "Factory" service is running and accepting connections on your machine. To launch it a Factory container with docker, run:

docker run --rm -it -v faktory-data:/var/lib/faktory -p -p contribsys/faktory:latest /faktory -b :7419 -w :7420

After that run the tests:

FAKTORY_URL=tcp:// cargo test --all-features --locked --all-targets

Please note that setting "FAKTORY_URL" environment variable is required for e2e tests to not be skipped.

Provided you have make installed and docker daemon running, you can launch a Faktory container with make faktory command. After that, hit make test/e2e to run the end-to-end test suite. Remove the container with make faktory/kill, if it's no longer needed.

To run end-to-end tests for the crate's tls feature, ensure you've got the compose docker plugin installed. Run make faktory/tls to spin up Faktory behind NGINX with ssl termination, then run make test/e2e/tls. To remove the containers, hit make faktory/tls/kill.


~232K SLoC