ora_client/
schedule_query.rsuse ora_proto::server::v1::{self, ScheduleQueryOrder};
use uuid::Uuid;
use crate::IndexSet;
#[derive(Debug, Clone, Default)]
#[must_use]
pub struct ScheduleFilter {
pub schedule_ids: IndexSet<Uuid>,
pub job_ids: IndexSet<Uuid>,
pub job_type_ids: IndexSet<String>,
pub labels: Vec<ScheduleLabelFilter>,
pub active: Option<bool>,
}
impl ScheduleFilter {
pub fn new() -> Self {
Self::default()
}
pub fn with_job_id(mut self, job_id: Uuid) -> Self {
self.job_ids.insert(job_id);
self
}
pub fn with_job_ids(mut self, job_ids: impl IntoIterator<Item = Uuid>) -> Self {
self.job_ids.extend(job_ids);
self
}
pub fn with_job_type_id(mut self, job_type_id: impl Into<String>) -> Self {
self.job_type_ids.insert(job_type_id.into());
self
}
pub fn with_job_type_ids(mut self, job_type_ids: impl IntoIterator<Item = String>) -> Self {
self.job_type_ids.extend(job_type_ids);
self
}
pub fn with_schedule_id(mut self, schedule_id: Uuid) -> Self {
self.schedule_ids.insert(schedule_id);
self
}
pub fn with_schedule_ids(mut self, schedule_ids: impl IntoIterator<Item = Uuid>) -> Self {
self.schedule_ids.extend(schedule_ids);
self
}
pub fn active_only(mut self) -> Self {
self.active = Some(true);
self
}
pub fn inactive_only(mut self) -> Self {
self.active = Some(false);
self
}
pub fn with_label_value(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.labels.push(ScheduleLabelFilter {
key: key.into(),
value: ScheduleLabelFilterValue::Equals(value.into()),
});
self
}
pub fn with_label(mut self, key: impl Into<String>) -> Self {
self.labels.push(ScheduleLabelFilter {
key: key.into(),
value: ScheduleLabelFilterValue::Exists,
});
self
}
}
impl From<ScheduleFilter> for v1::ScheduleQueryFilter {
fn from(filter: ScheduleFilter) -> Self {
Self {
job_ids: filter
.job_ids
.into_iter()
.map(|id| id.to_string())
.collect(),
job_type_ids: filter
.job_type_ids
.into_iter()
.map(|id| id.to_string())
.collect(),
schedule_ids: filter
.schedule_ids
.into_iter()
.map(|id| id.to_string())
.collect(),
labels: filter.labels.into_iter().map(Into::into).collect(),
active: filter.active,
}
}
}
#[derive(Debug, Clone)]
pub struct ScheduleLabelFilter {
pub key: String,
pub value: ScheduleLabelFilterValue,
}
#[derive(Debug, Clone)]
pub enum ScheduleLabelFilterValue {
Exists,
Equals(String),
}
impl From<ScheduleLabelFilter> for v1::ScheduleLabelFilter {
fn from(filter: ScheduleLabelFilter) -> Self {
Self {
key: filter.key,
value: match filter.value {
ScheduleLabelFilterValue::Exists => Some(v1::schedule_label_filter::Value::Exists(
v1::LabelFilterExistCondition::Exists.into(),
)),
ScheduleLabelFilterValue::Equals(value) => {
Some(v1::schedule_label_filter::Value::Equals(value))
}
},
}
}
}
#[derive(Debug, Default, Clone, Copy)]
pub enum ScheduleOrder {
CreatedAtAsc,
#[default]
CreatedAtDesc,
}
impl From<ScheduleOrder> for ScheduleQueryOrder {
fn from(value: ScheduleOrder) -> Self {
match value {
ScheduleOrder::CreatedAtAsc => Self::CreatedAtAsc,
ScheduleOrder::CreatedAtDesc => Self::CreatedAtDesc,
}
}
}