Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub batch_size: usize,
    pub heartbeat_interval: Duration,
    pub missed_heartbeats: usize,
    pub queue: Queue,
    pub database_url: Option<String>,
    pub lock_tasks: bool,
    pub persist_results: bool,
}
Expand description

Configuration for a worker’s queue, batching, and liveness detection.

Config controls how jobs are fetched from a queue and how worker liveness is monitored.

§Defaults

  • batch_size: 10
  • heartbeat_interval: 30 seconds
  • missed_heartbeats: 2
  • queue: "default"
  • database_url: None
  • lock_tasks: true
  • persist_results: true

Fields§

§batch_size: usize

The maximum number of jobs fetched in a single batch.

Must be greater than zero.

§heartbeat_interval: Duration

The interval between worker heartbeats.

§missed_heartbeats: usize

The number of missed heartbeats allowed before a worker is considered dead.

§queue: Queue

The queue from which jobs are consumed.

§database_url: Option<String>

An optional database URL used by the worker.

§lock_tasks: bool

Whether tasks should be locked while being processed.

§persist_results: bool

Whether job results should be persisted.

Implementations§

Source§

impl Config

Source

pub fn batch_size(self, size: usize) -> Self

Sets the maximum number of jobs to fetch in a single batch.

Larger batches can improve throughput by reducing the number of queue operations, while smaller batches can reduce memory usage and improve job distribution between workers.

§Panics

Panics if size is 0.

§Examples
use apalis_sqlite::Config;

let config = Config::default().batch_size(50);

assert_eq!(config.batch_size, 50);
Source

pub fn heartbeat_interval(self, interval: Duration) -> Self

Sets the interval between worker heartbeats.

A shorter interval detects failed workers sooner but produces heartbeat activity more frequently.

§Examples
use std::time::Duration;
use apalis_sqlite::Config;

let config = Config::default()
    .heartbeat_interval(Duration::from_secs(15));

assert_eq!(config.heartbeat_interval, Duration::from_secs(15));
Source

pub fn queue(self, queue: impl AsRef<str>) -> Self

Sets the queue from which jobs are consumed.

§Examples
let config = Config::default()
    .queue("high-priority");

assert_eq!(config.queue.as_ref(), "high-priority");
Source

pub fn missed_heartbeats(self, missed_heartbeats: usize) -> Self

Sets the number of missed heartbeats allowed before a worker is considered dead.

This value works together with Self::heartbeat_interval. For example, a 30-second heartbeat interval with 2 missed heartbeats results in an orphan timeout of 60 seconds.

§Examples
use apalis_sqlite::Config;

let config = Config::default().missed_heartbeats(3);

assert_eq!(config.missed_heartbeats, 3);
assert_eq!(
    config.orphaned_duration(),
    std::time::Duration::from_secs(90)
);
Source

pub fn database_url(self, database_url: impl Into<String>) -> Self

Sets the database URL used by the worker.

§Examples
use apalis_sqlite::Config;

let config = Config::default()
    .database_url(":memory:");

assert_eq!(
    config.database_url.as_deref(),
    Some(":memory:")
);
Source

pub fn lock_tasks(self, lock_tasks: bool) -> Self

Enables or disables task locking.

When enabled, tasks are locked while being processed to prevent multiple workers from processing the same task concurrently.

§Examples
use apalis_sqlite::Config;

let config = Config::default().lock_tasks(false);

assert!(!config.lock_tasks);
Source

pub fn persist_results(self, persist_results: bool) -> Self

Enables or disables result persistence.

When enabled, results produced by completed jobs are persisted.

§Examples
use apalis_sqlite::Config;

let config = Config::default().persist_results(false);

assert!(!config.persist_results);
Source

pub fn orphaned_duration(&self) -> Duration

Returns the amount of time after which a worker may be considered orphaned.

The duration is calculated as:

heartbeat_interval × missed_heartbeats

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Config

Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more