1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/// Redis key generator for Jono components
#[derive(Clone)]
pub struct Keys {
prefix: String,
topic: String,
}
impl Keys {
/// Create a new Redis key generator with the default "jono" prefix and over given topic
pub fn with_topic(topic: &str) -> Self {
Self {
prefix: "jono".to_string(),
topic: topic.to_string(),
}
}
/// Redis key for the sorted set that holds queued jobs
pub fn queued_set(&self) -> String {
format!("{}:{}:queued", self.prefix, self.topic)
}
/// Redis key for the sorted set that holds running jobs
pub fn running_set(&self) -> String {
format!("{}:{}:running", self.prefix, self.topic)
}
/// Redis key for the sorted set that communicates which jobs have been canceled
pub fn canceled_set(&self) -> String {
format!("{}:{}:canceled", self.prefix, self.topic)
}
/// Redis key for the sorted set that holds the jobs scheduled to run later
pub fn scheduled_set(&self) -> String {
format!("{}:{}:scheduled", self.prefix, self.topic)
}
/// Redis key for the hash that holds job metadata
pub fn job_metadata_hash(&self, job_id: &str) -> String {
format!("{}:{}:job:{}", self.prefix, self.topic, job_id)
}
}