use std::time::Duration;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct HandlerLimits {
pub max_id_length: usize,
pub max_metadata_size: usize,
pub max_cancellation_tokens: usize,
pub max_token_age: Duration,
pub push_delivery_timeout: Duration,
pub push_delivery_budget: Duration,
pub executor_drain_timeout: Duration,
pub max_artifacts_per_task: usize,
pub max_context_locks: usize,
pub max_push_configs_per_task: usize,
pub max_parts_per_artifact: usize,
pub max_total_push_configs: usize,
pub subscribe_reattach_interval: Duration,
pub subscribe_max_idle: Duration,
pub subscribe_replay_limit: usize,
pub subscribe_replay_catchup: Duration,
}
impl Default for HandlerLimits {
fn default() -> Self {
Self {
max_id_length: 1024,
max_metadata_size: 1_048_576,
max_cancellation_tokens: 10_000,
max_token_age: Duration::from_secs(3600),
push_delivery_timeout: Duration::from_secs(5),
push_delivery_budget: Duration::from_secs(30),
executor_drain_timeout: Duration::from_secs(5),
max_artifacts_per_task: 1000,
max_context_locks: 10_000,
max_push_configs_per_task: 100,
max_parts_per_artifact: 10_000,
max_total_push_configs: 100_000,
subscribe_reattach_interval: Duration::from_millis(250),
subscribe_max_idle: Duration::from_secs(300),
subscribe_replay_limit: 1_000,
subscribe_replay_catchup: Duration::from_secs(2),
}
}
}
pub const MIN_MESSAGE_ID_LENGTH: usize = 36;
impl HandlerLimits {
#[must_use]
pub const fn effective_max_message_id_length(&self) -> usize {
MIN_MESSAGE_ID_LENGTH + self.max_id_length.saturating_sub(MIN_MESSAGE_ID_LENGTH)
}
#[must_use]
pub const fn with_subscribe_reattach_interval(mut self, interval: Duration) -> Self {
self.subscribe_reattach_interval = interval;
self
}
#[must_use]
pub const fn with_subscribe_max_idle(mut self, max_idle: Duration) -> Self {
self.subscribe_max_idle = max_idle;
self
}
#[must_use]
pub const fn with_subscribe_replay_limit(mut self, limit: usize) -> Self {
self.subscribe_replay_limit = limit;
self
}
#[must_use]
pub const fn with_subscribe_replay_catchup(mut self, catchup: Duration) -> Self {
self.subscribe_replay_catchup = catchup;
self
}
#[must_use]
pub const fn with_max_id_length(mut self, length: usize) -> Self {
self.max_id_length = length;
self
}
#[must_use]
pub const fn with_max_metadata_size(mut self, size: usize) -> Self {
self.max_metadata_size = size;
self
}
#[must_use]
pub const fn with_max_cancellation_tokens(mut self, max: usize) -> Self {
self.max_cancellation_tokens = max;
self
}
#[must_use]
pub const fn with_max_token_age(mut self, age: Duration) -> Self {
self.max_token_age = age;
self
}
#[must_use]
pub const fn with_push_delivery_timeout(mut self, timeout: Duration) -> Self {
self.push_delivery_timeout = timeout;
self
}
#[must_use]
pub const fn with_push_delivery_budget(mut self, budget: Duration) -> Self {
self.push_delivery_budget = budget;
self
}
#[must_use]
pub const fn with_executor_drain_timeout(mut self, timeout: Duration) -> Self {
self.executor_drain_timeout = timeout;
self
}
#[must_use]
pub const fn with_max_artifacts_per_task(mut self, max: usize) -> Self {
self.max_artifacts_per_task = max;
self
}
#[must_use]
pub const fn with_max_push_configs_per_task(mut self, max: usize) -> Self {
self.max_push_configs_per_task = max;
self
}
#[must_use]
pub const fn with_max_total_push_configs(mut self, max: usize) -> Self {
self.max_total_push_configs = max;
self
}
#[must_use]
pub const fn with_max_parts_per_artifact(mut self, max: usize) -> Self {
self.max_parts_per_artifact = max;
self
}
#[must_use]
pub const fn with_max_context_locks(mut self, max: usize) -> Self {
self.max_context_locks = max;
self
}
}
#[cfg(test)]
mod tests;