use std::time::Duration;
use crate::WorkerConfig;
pub struct WorkerBuilder {
num_workers: usize,
max_queue_size: usize,
scheduler_interval: Duration,
task_timeout_warning: Duration,
}
impl Default for WorkerBuilder {
fn default() -> Self {
Self::new()
}
}
impl WorkerBuilder {
pub fn new() -> Self {
Self {
num_workers: 1,
max_queue_size: 10000,
scheduler_interval: Duration::from_millis(10),
task_timeout_warning: Duration::from_secs(30),
}
}
pub fn num_workers(mut self, workers: usize) -> Self {
self.num_workers = workers.max(1);
self
}
pub fn max_queue_size(mut self, size: usize) -> Self {
self.max_queue_size = size.max(1);
self
}
pub fn scheduler_interval(mut self, interval: Duration) -> Self {
self.scheduler_interval = interval;
self
}
pub fn task_timeout_warning(mut self, timeout: Duration) -> Self {
self.task_timeout_warning = timeout;
self
}
pub fn build(self) -> WorkerConfig {
WorkerConfig {
num_workers: self.num_workers,
max_queue_size: self.max_queue_size,
scheduler_interval: self.scheduler_interval,
task_timeout_warning: self.task_timeout_warning,
}
}
}