reifydb_sub_worker/
builder.rs1use std::time::Duration;
7
8use crate::WorkerConfig;
9
10pub struct WorkerBuilder {
12 num_workers: usize,
13 max_queue_size: usize,
14 scheduler_interval: Duration,
15 task_timeout_warning: Duration,
16}
17
18impl Default for WorkerBuilder {
19 fn default() -> Self {
20 Self::new()
21 }
22}
23
24impl WorkerBuilder {
25 pub fn new() -> Self {
27 Self {
28 num_workers: 1,
29 max_queue_size: 10000,
30 scheduler_interval: Duration::from_millis(10),
31 task_timeout_warning: Duration::from_secs(30),
32 }
33 }
34
35 pub fn num_workers(mut self, workers: usize) -> Self {
39 self.num_workers = workers.max(1);
40 self
41 }
42
43 pub fn max_queue_size(mut self, size: usize) -> Self {
47 self.max_queue_size = size.max(1);
48 self
49 }
50
51 pub fn scheduler_interval(mut self, interval: Duration) -> Self {
55 self.scheduler_interval = interval;
56 self
57 }
58
59 pub fn task_timeout_warning(mut self, timeout: Duration) -> Self {
63 self.task_timeout_warning = timeout;
64 self
65 }
66
67 pub fn build(self) -> WorkerConfig {
69 WorkerConfig {
70 num_workers: self.num_workers,
71 max_queue_size: self.max_queue_size,
72 scheduler_interval: self.scheduler_interval,
73 task_timeout_warning: self.task_timeout_warning,
74 }
75 }
76}