Rust

server

Module

The worker server: jobs per queue, hooks around them, and the consume loops that run them.

Contents

use utopia_queue::Server;
Rust
pub struct Server

A worker server: register a Job per queue, hooks to run around them, then Server::start.

For each message: the * init hooks (unless the job turned hooks off) and the init hooks of the job's groups run, then the job; a failure rejects the message (terminally for Error::PermanentFailure, Error::Type and Error::Value) and runs the error hooks; success commits it and runs the shutdown hooks. Hooks and jobs read params from the payload and inject resources (message, error, workerId, and anything set on Server::resources).

Rust
use std::sync::Arc;
use utopia_queue::adapter::{Adapter, Runtime};
use utopia_queue::broker::Redis;
use utopia_queue::connection::Redis as Connection;
use utopia_queue::Server;

let broker = Arc::new(Redis::new(Arc::new(Connection::new("localhost", 6379)), Arc::new(Connection::new("localhost", 6379))));
let mut server = Server::new(Adapter::new(broker, 1, Runtime::Workers));
server.job("emails", 4, None)?.inject("message").action(|scope| async move {
    let _message = scope.message();
    Ok(())
});
std::sync::Arc::new(server).start().await?;
Compiles in CI; needs a running service to execute.
Rust
pub type ConsumerFactory = crate::adapter::ConsumerFactory

Makes the consumer for one queue, overriding the adapter's.

Rust
pub const DURATION_BUCKETS: [f64; 24] = [ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0, 20.0, 30.0, 60.0, 120.0, 300.0, 600.0, 1200.0, 1800.0, 3600.0, 7200.0, ]

Bucket boundaries of the duration histograms, in seconds: a queue spans milliseconds to hours of backlog.

Rust
pub const SIZE_BUCKETS: [f64; 10] = [1024.0, 4096.0, 16384.0, 65536.0, 262_144.0, 1_048_576.0, 4_194_304.0, 16_777_216.0, 67_108_864.0, 268_435_456.0]

Bucket boundaries of the message size histogram, in bytes: 1 KiB to 256 MiB.