pgboss-rs
Queue jobs with Rust and PostgreSQL like a boss
Inspired by, compatible with and partially ported from pg-boss Node.js package.
Heavily influenced by decisions and approaches in faktory-rs crate.
use Duration;
use json;
use ;
// Create a client first.
let client = builder
.schema
.connect
.await
.unwrap;
// Then create a dlq (optional) and a queue.
c.create_standard_queue.await.unwrap;
// NB! queue should be created before pushing jobs
let queue = builder
.name
.dead_letter
.partition
.build;
c.create_queue.await.unwrap;
// Build a job ...
let job = builder
.queue_name // which queue this job should be sent to
.data // arbitrary json, your job's payload
.priority // will be consumer prior to those with lower priorities
.retry_limit // only retry this job once
.retry_delay // do not retry immediately after failure
.expire_in // only give the worker 5 minutes to complete the job
.retain_for // do not archive for at least 1 day
.delay_for // make it visible to consumers after 5 seconds
.singleton_for // only allow one job for at least 7 seconds
.singleton_key // allow more than one job if their key is different from this
.build;
// ... and enqueue it.
let _id = c.send_job.await.expect;
// Consume from the queue.
let fetched_job = c
.fetch_job
.await
.expect
.expect;
assert_eq!;
assert_eq!;
// report on the processing results
c
.complete_job
.await
.unwrap;