use std::time::Duration;
#[derive(Clone, Debug)]
pub struct RateLimiter {
pub limit: i64,
pub period: Duration,
}
#[derive(Clone, Debug)]
pub struct WorkflowQueue {
pub name: String,
pub worker_concurrency: Option<usize>,
pub global_concurrency: Option<i64>,
pub priority_enabled: bool,
pub rate_limit: Option<RateLimiter>,
pub max_tasks_per_iteration: usize,
pub partitioned: bool,
pub base_polling_interval: Duration,
pub max_polling_interval: Duration,
}
impl WorkflowQueue {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
worker_concurrency: None,
global_concurrency: None,
priority_enabled: false,
rate_limit: None,
max_tasks_per_iteration: 100,
partitioned: false,
base_polling_interval: Duration::from_secs(1),
max_polling_interval: Duration::from_secs(120),
}
}
pub fn worker_concurrency(mut self, n: usize) -> Self {
self.worker_concurrency = Some(n);
self
}
pub fn global_concurrency(mut self, n: i64) -> Self {
self.global_concurrency = Some(n);
self
}
pub fn priority_enabled(mut self) -> Self {
self.priority_enabled = true;
self
}
pub fn rate_limiter(mut self, r: RateLimiter) -> Self {
self.rate_limit = Some(r);
self
}
pub fn max_tasks_per_iteration(mut self, n: usize) -> Self {
self.max_tasks_per_iteration = n;
self
}
pub fn partitioned(mut self) -> Self {
self.partitioned = true;
self
}
pub fn base_polling_interval(mut self, d: Duration) -> Self {
self.base_polling_interval = d;
self
}
pub fn max_polling_interval(mut self, d: Duration) -> Self {
self.max_polling_interval = d;
self
}
}