use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
#[serde(default, deny_unknown_fields)]
pub struct QueueAgingThresholds {
#[schemars(range(min = 0, max = 3650))]
pub warning_days: Option<u32>,
#[schemars(range(min = 0, max = 3650))]
pub stale_days: Option<u32>,
#[schemars(range(min = 0, max = 3650))]
pub rotten_days: Option<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
#[serde(default, deny_unknown_fields)]
pub struct QueueConfig {
pub file: Option<PathBuf>,
pub done_file: Option<PathBuf>,
pub id_prefix: Option<String>,
#[schemars(range(min = 1, max = 255))]
pub id_width: Option<u8>,
#[schemars(range(min = 100, max = 10000))]
pub size_warning_threshold_kb: Option<u32>,
#[schemars(range(min = 50, max = 5000))]
pub task_count_warning_threshold: Option<u32>,
#[schemars(range(min = 1, max = 100))]
pub max_dependency_depth: Option<u8>,
#[schemars(range(min = 0, max = 3650))]
pub auto_archive_terminal_after_days: Option<u32>,
pub aging_thresholds: Option<QueueAgingThresholds>,
}
impl QueueConfig {
pub fn merge_from(&mut self, other: Self) {
if other.file.is_some() {
self.file = other.file;
}
if other.done_file.is_some() {
self.done_file = other.done_file;
}
if other.id_prefix.is_some() {
self.id_prefix = other.id_prefix;
}
if other.id_width.is_some() {
self.id_width = other.id_width;
}
if other.size_warning_threshold_kb.is_some() {
self.size_warning_threshold_kb = other.size_warning_threshold_kb;
}
if other.task_count_warning_threshold.is_some() {
self.task_count_warning_threshold = other.task_count_warning_threshold;
}
if other.max_dependency_depth.is_some() {
self.max_dependency_depth = other.max_dependency_depth;
}
if other.auto_archive_terminal_after_days.is_some() {
self.auto_archive_terminal_after_days = other.auto_archive_terminal_after_days;
}
if other.aging_thresholds.is_some() {
self.aging_thresholds = other.aging_thresholds;
}
}
}