apalis_libsql/
config.rs

1//! Configuration for LibsqlStorage
2
3use std::time::Duration;
4
5use apalis_core::backend::queue::Queue;
6
7/// Configuration for the LibsqlStorage backend
8#[derive(Debug, Clone)]
9pub struct Config {
10    queue: Queue,
11    buffer_size: usize,
12    poll_interval: Duration,
13    keep_alive: Duration,
14    reenqueue_orphaned_after: Duration,
15}
16
17impl Config {
18    /// Create a new config with the given queue name
19    #[must_use]
20    pub fn new(queue: impl Into<String>) -> Self {
21        Self {
22            queue: Queue::from(queue.into()),
23            buffer_size: 10,
24            poll_interval: Duration::from_millis(100),
25            keep_alive: Duration::from_secs(30),
26            reenqueue_orphaned_after: Duration::from_secs(300),
27        }
28    }
29
30    /// Get the queue
31    #[must_use]
32    pub fn queue(&self) -> &Queue {
33        &self.queue
34    }
35
36    /// Get the buffer size
37    #[must_use]
38    pub fn buffer_size(&self) -> usize {
39        self.buffer_size
40    }
41
42    /// Set the buffer size
43    ///
44    /// # Panics
45    ///
46    /// Panics if `size` is 0.
47    #[must_use]
48    pub fn set_buffer_size(mut self, size: usize) -> Self {
49        assert!(size > 0, "Buffer size must be greater than 0");
50        self.buffer_size = size;
51        self
52    }
53
54    /// Get the poll interval
55    #[must_use]
56    pub fn poll_interval(&self) -> Duration {
57        self.poll_interval
58    }
59
60    /// Set the poll interval
61    #[must_use]
62    pub fn set_poll_interval(mut self, interval: Duration) -> Self {
63        self.poll_interval = interval;
64        self
65    }
66
67    /// Get the keep alive interval
68    #[must_use]
69    pub fn keep_alive(&self) -> Duration {
70        self.keep_alive
71    }
72
73    /// Set the keep alive interval
74    #[must_use]
75    pub fn set_keep_alive(mut self, interval: Duration) -> Self {
76        self.keep_alive = interval;
77        self
78    }
79
80    /// Get the duration after which orphaned tasks are re-enqueued
81    #[must_use]
82    pub fn reenqueue_orphaned_after(&self) -> Duration {
83        self.reenqueue_orphaned_after
84    }
85
86    /// Set the duration after which orphaned tasks are re-enqueued
87    #[must_use]
88    pub fn set_reenqueue_orphaned_after(mut self, duration: Duration) -> Self {
89        self.reenqueue_orphaned_after = duration;
90        self
91    }
92}