1use std::path::PathBuf;
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
9pub struct QueueConfig {
10 pub db_path: Option<PathBuf>,
12
13 pub worker_id: String,
15
16 pub cooldown: Duration,
18
19 pub max_consecutive: u32,
21
22 pub poll_interval: Duration,
24
25 pub heartbeat_interval: Duration,
27
28 pub stale_after: Duration,
30
31 pub max_retries: u32,
33}
34
35impl Default for QueueConfig {
36 fn default() -> Self {
37 Self {
38 db_path: None,
39 worker_id: format!("worker-{}", uuid::Uuid::new_v4()),
40 cooldown: Duration::from_secs(0),
41 max_consecutive: 0,
42 poll_interval: Duration::from_secs(3),
43 heartbeat_interval: Duration::from_secs(10),
44 stale_after: Duration::from_secs(300),
45 max_retries: 3,
46 }
47 }
48}
49
50impl QueueConfig {
51 pub fn builder() -> QueueConfigBuilder {
53 QueueConfigBuilder::default()
54 }
55}
56
57#[derive(Default)]
59pub struct QueueConfigBuilder {
60 config: QueueConfig,
61}
62
63impl QueueConfigBuilder {
64 pub fn with_db_path(mut self, path: PathBuf) -> Self {
66 self.config.db_path = Some(path);
67 self
68 }
69
70 pub fn with_worker_id(mut self, worker_id: impl Into<String>) -> Self {
72 self.config.worker_id = worker_id.into();
73 self
74 }
75
76 pub fn with_cooldown(mut self, duration: Duration) -> Self {
78 self.config.cooldown = duration;
79 self
80 }
81
82 pub fn with_max_consecutive(mut self, max: u32) -> Self {
84 self.config.max_consecutive = max;
85 self
86 }
87
88 pub fn with_poll_interval(mut self, interval: Duration) -> Self {
90 self.config.poll_interval = interval;
91 self
92 }
93
94 pub fn with_heartbeat_interval(mut self, interval: Duration) -> Self {
96 self.config.heartbeat_interval = interval;
97 self
98 }
99
100 pub fn with_stale_after(mut self, duration: Duration) -> Self {
102 self.config.stale_after = duration;
103 self
104 }
105
106 pub fn with_max_retries(mut self, max_retries: u32) -> Self {
108 self.config.max_retries = max_retries;
109 self
110 }
111
112 pub fn build(self) -> QueueConfig {
114 self.config
115 }
116}