use std::sync::Arc;
use thiserror::Error;
#[derive(Error, Debug, PartialEq, Eq)]
pub enum InvalidQueueName {
#[error("queue name can't contain a colon, as that's a separator used by redis")]
Colon,
#[error("queue name can't be empty")]
Empty,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueueName(Arc<str>);
impl QueueName {
pub fn new(name: impl ToString) -> Result<Self, InvalidQueueName> {
let name = name.to_string().trim().to_string();
if name.contains(":") {
return Err(InvalidQueueName::Colon);
}
if name.is_empty() {
return Err(InvalidQueueName::Empty);
}
Ok(Self(Arc::from(name)))
}
pub fn as_str(&self) -> &str {
&self.0
}
pub(crate) fn active(&self) -> String {
format!("bull:{}:active", self.0)
}
pub(crate) fn completed(&self) -> String {
format!("bull:{}:completed", self.0)
}
pub(crate) fn delayed(&self) -> String {
format!("bull:{}:delayed", self.0)
}
pub(crate) fn events(&self) -> String {
format!("bull:{}:events", self.0)
}
pub(crate) fn failed(&self) -> String {
format!("bull:{}:failed", self.0)
}
pub(crate) fn id(&self) -> String {
format!("bull:{}:id", self.0)
}
pub(crate) fn job(&self, job_id: &str) -> String {
format!("bull:{}:{}", self.0, job_id)
}
pub(crate) fn job_lock(&self, job_id: &str) -> String {
format!("bull:{}:{}:lock", self.0, job_id)
}
pub(crate) fn job_logs(&self, job_id: &str) -> String {
format!("bull:{}:{}:logs", self.0, job_id)
}
pub(crate) fn limiter(&self) -> String {
format!("bull:{}:limiter", self.0)
}
pub(crate) fn marker(&self) -> String {
format!("bull:{}:marker", self.0)
}
pub(crate) fn meta(&self) -> String {
format!("bull:{}:meta", self.0)
}
pub(crate) fn paused(&self) -> String {
format!("bull:{}:paused", self.0)
}
pub(crate) fn prefix(&self) -> String {
format!("bull:{}:", self.0)
}
pub(crate) fn prioritized(&self) -> String {
format!("bull:{}:prioritized", self.0)
}
pub(crate) fn priority_counter(&self) -> String {
format!("bull:{}:pc", self.0)
}
pub(crate) fn stalled(&self) -> String {
format!("bull:{}:stalled", self.0)
}
pub(crate) fn stalled_check(&self) -> String {
format!("bull:{}:stalled-check", self.0)
}
pub(crate) fn wait(&self) -> String {
format!("bull:{}:wait", self.0)
}
pub(crate) fn metrics(&self) -> String {
format!("bull:{}:metrics", self.0)
}
pub(crate) fn base(&self) -> String {
format!("bull:{}:", self.0)
}
}