use std::time::Duration;
use apalis_core::backend::queue::Queue;
#[derive(Debug, Clone)]
pub struct Config {
queue: Queue,
buffer_size: usize,
poll_interval: Duration,
keep_alive: Duration,
reenqueue_orphaned_after: Duration,
}
impl Config {
#[must_use]
pub fn new(queue: impl Into<String>) -> Self {
Self {
queue: Queue::from(queue.into()),
buffer_size: 10,
poll_interval: Duration::from_millis(100),
keep_alive: Duration::from_secs(30),
reenqueue_orphaned_after: Duration::from_secs(300),
}
}
#[must_use]
pub fn queue(&self) -> &Queue {
&self.queue
}
#[must_use]
pub fn buffer_size(&self) -> usize {
self.buffer_size
}
#[must_use]
pub fn set_buffer_size(mut self, size: usize) -> Self {
assert!(size > 0, "Buffer size must be greater than 0");
self.buffer_size = size;
self
}
#[must_use]
pub fn poll_interval(&self) -> Duration {
self.poll_interval
}
#[must_use]
pub fn set_poll_interval(mut self, interval: Duration) -> Self {
self.poll_interval = interval;
self
}
#[must_use]
pub fn keep_alive(&self) -> Duration {
self.keep_alive
}
#[must_use]
pub fn set_keep_alive(mut self, interval: Duration) -> Self {
self.keep_alive = interval;
self
}
#[must_use]
pub fn reenqueue_orphaned_after(&self) -> Duration {
self.reenqueue_orphaned_after
}
#[must_use]
pub fn set_reenqueue_orphaned_after(mut self, duration: Duration) -> Self {
self.reenqueue_orphaned_after = duration;
self
}
}