use std::time::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum FailurePolicy {
#[default]
Fail,
Skip,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ApplyOpts {
pub max_in_flight: usize,
pub batch_size: usize,
pub batch_max_wait: Duration,
pub timeout: Duration,
pub failure_policy: FailurePolicy,
}
impl Default for ApplyOpts {
fn default() -> Self {
Self {
max_in_flight: 1,
batch_size: 1000,
batch_max_wait: Duration::from_millis(500),
timeout: Duration::from_secs(60),
failure_policy: FailurePolicy::Fail,
}
}
}
impl ApplyOpts {
pub fn identity() -> Self {
Self::default().with_batch_size(1).with_max_in_flight(1)
}
pub fn with_max_in_flight(mut self, n: usize) -> Self {
self.max_in_flight = n.max(1);
self
}
pub fn with_batch_size(mut self, n: usize) -> Self {
self.batch_size = n.max(1);
self
}
pub fn with_batch_max_wait(mut self, d: Duration) -> Self {
self.batch_max_wait = d;
self
}
pub fn with_timeout(mut self, d: Duration) -> Self {
self.timeout = d;
self
}
pub fn with_failure_policy(mut self, policy: FailurePolicy) -> Self {
self.failure_policy = policy;
self
}
}