Expand description
PostgreSQL QueueBackend for Boson.
When to use: shared durable state for Mode 1 or Mode 2 (enqueue hosts + worker binaries
against the same database). Enable via the boson crate postgres feature.
Mode 2 workers should set a unique worker_id and lease_ttl_secs > 0. See the
boson crate
Mode 2.
§Entry points
PostgresQueueBackend::connect— open a pool and bootstrap schemainstall_default_postgres_backend— register on the globalQueueRouter
§Mode 2 — Enqueue binary
Shared DATABASE_URL with the worker. No claim loop in this process:
use std::sync::Arc;
use boson_backend_postgres::PostgresQueueBackend;
use boson_core::JsonExecutionContextFactory;
use boson_runtime::{configure, Boson};
let url = std::env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgres://localhost/boson".into());
let backend = PostgresQueueBackend::connect(&url).await?;
let boson = Boson::builder()
.queue_backend(Arc::new(backend))
.execution_context_factory(JsonExecutionContextFactory)
.auto_registry()
.without_worker()
.build()?;
configure(boson);
// MyTask::send_with(...).await?;§Mode 2 — Worker binary
Same database URL, unique worker_id, and lease_ttl_secs > 0:
use std::sync::Arc;
use boson_backend_postgres::PostgresQueueBackend;
use boson_core::JsonExecutionContextFactory;
use boson_runtime::Boson;
let url = std::env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgres://localhost/boson".into());
let backend = PostgresQueueBackend::connect(&url).await?;
let _boson = Boson::builder()
.queue_backend(Arc::new(backend))
.execution_context_factory(JsonExecutionContextFactory)
.worker_id(std::env::var("BOSON_WORKER_ID").unwrap_or_else(|_| "worker-1".into()))
.lease_ttl_secs(30)
.auto_registry()
.build()?;Structs§
- Postgres
Queue Backend - PostgreSQL-backed queue backend.
Functions§
- install_
default_ postgres_ backend - Install a new
PostgresQueueBackendas the process-global default backend. - install_
isolated_ postgres_ backend - Install postgres backend with an isolated schema for test sessions.
- postgres_
test_ url - Resolve postgres URL from env (test preferred, then bench, then default).