use std::path::PathBuf;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct QueueConfig {
pub db_path: Option<PathBuf>,
pub worker_id: String,
pub cooldown: Duration,
pub max_consecutive: u32,
pub poll_interval: Duration,
pub heartbeat_interval: Duration,
pub stale_after: Duration,
pub max_retries: u32,
}
impl Default for QueueConfig {
fn default() -> Self {
Self {
db_path: None,
worker_id: format!("worker-{}", uuid::Uuid::new_v4()),
cooldown: Duration::from_secs(0),
max_consecutive: 0,
poll_interval: Duration::from_secs(3),
heartbeat_interval: Duration::from_secs(10),
stale_after: Duration::from_secs(300),
max_retries: 3,
}
}
}
impl QueueConfig {
pub fn builder() -> QueueConfigBuilder {
QueueConfigBuilder::default()
}
}
#[derive(Default)]
pub struct QueueConfigBuilder {
config: QueueConfig,
}
impl QueueConfigBuilder {
pub fn with_db_path(mut self, path: PathBuf) -> Self {
self.config.db_path = Some(path);
self
}
pub fn with_worker_id(mut self, worker_id: impl Into<String>) -> Self {
self.config.worker_id = worker_id.into();
self
}
pub fn with_cooldown(mut self, duration: Duration) -> Self {
self.config.cooldown = duration;
self
}
pub fn with_max_consecutive(mut self, max: u32) -> Self {
self.config.max_consecutive = max;
self
}
pub fn with_poll_interval(mut self, interval: Duration) -> Self {
self.config.poll_interval = interval;
self
}
pub fn with_heartbeat_interval(mut self, interval: Duration) -> Self {
self.config.heartbeat_interval = interval;
self
}
pub fn with_stale_after(mut self, duration: Duration) -> Self {
self.config.stale_after = duration;
self
}
pub fn with_max_retries(mut self, max_retries: u32) -> Self {
self.config.max_retries = max_retries;
self
}
pub fn build(self) -> QueueConfig {
self.config
}
}