remora/crates/remora-coordination/src/keys.rs

54 lines
1.2 KiB
Rust

//! Namespaced keys for queue, reservation, lease, progress, cancellation, and permits.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct KeySpace {
prefix: String,
}
impl KeySpace {
pub fn new(prefix: impl Into<String>) -> Self {
Self {
prefix: prefix.into(),
}
}
#[must_use]
pub fn prefix(&self) -> &str {
&self.prefix
}
#[must_use]
pub fn queue(&self) -> String {
format!("{}queue", self.prefix)
}
#[must_use]
pub fn queue_members(&self) -> String {
format!("{}queue:members", self.prefix)
}
#[must_use]
pub fn reserve(&self, job_id: &str) -> String {
format!("{}reserve:{job_id}", self.prefix)
}
#[must_use]
pub fn lease(&self, job_id: &str) -> String {
format!("{}lease:{job_id}", self.prefix)
}
#[must_use]
pub fn progress(&self, job_id: &str) -> String {
format!("{}progress:{job_id}", self.prefix)
}
#[must_use]
pub fn cancel(&self, job_id: &str) -> String {
format!("{}cancel:{job_id}", self.prefix)
}
#[must_use]
pub fn permit_slots(&self) -> String {
format!("{}permit:slots", self.prefix)
}
}