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:10heartbeat_interval:30secondsmissed_heartbeats:2queue:"default"database_url:Nonelock_tasks:truepersist_results:true
Fields§
§batch_size: usizeThe maximum number of jobs fetched in a single batch.
Must be greater than zero.
heartbeat_interval: DurationThe interval between worker heartbeats.
missed_heartbeats: usizeThe number of missed heartbeats allowed before a worker is considered dead.
queue: QueueThe queue from which jobs are consumed.
database_url: Option<String>An optional database URL used by the worker.
lock_tasks: boolWhether tasks should be locked while being processed.
persist_results: boolWhether job results should be persisted.
Implementations§
Source§impl Config
impl Config
Sourcepub fn batch_size(self, size: usize) -> Self
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);Sourcepub fn heartbeat_interval(self, interval: Duration) -> Self
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));Sourcepub fn queue(self, queue: impl AsRef<str>) -> Self
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");Sourcepub fn missed_heartbeats(self, missed_heartbeats: usize) -> Self
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)
);Sourcepub fn database_url(self, database_url: impl Into<String>) -> Self
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:")
);Sourcepub fn lock_tasks(self, lock_tasks: bool) -> Self
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);Sourcepub fn persist_results(self, persist_results: bool) -> Self
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);Sourcepub fn orphaned_duration(&self) -> Duration
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_heartbeatsTrait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Config
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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