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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use std::{fmt::Display, num::NonZeroUsize};
use enum_iterator::IntoEnumIterator;
use serde::Serialize;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, IntoEnumIterator, PartialOrd, Ord, Serialize)]
pub enum QueueKind {
NetworkIncoming,
Network,
Regular,
Api,
}
impl Display for QueueKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str_value = match self {
QueueKind::NetworkIncoming => "NetworkIncoming",
QueueKind::Network => "Network",
QueueKind::Regular => "Regular",
QueueKind::Api => "Api",
};
write!(f, "{}", str_value)
}
}
impl Default for QueueKind {
fn default() -> Self {
QueueKind::Regular
}
}
impl QueueKind {
fn weight(self) -> NonZeroUsize {
NonZeroUsize::new(match self {
QueueKind::NetworkIncoming => 4,
QueueKind::Network => 4,
QueueKind::Regular => 8,
QueueKind::Api => 16,
})
.expect("weight must be positive")
}
pub(crate) fn weights() -> Vec<(Self, NonZeroUsize)> {
QueueKind::into_enum_iter()
.map(|q| (q, q.weight()))
.collect()
}
pub(crate) fn metrics_name(&self) -> &str {
match self {
QueueKind::NetworkIncoming => "network_incoming",
QueueKind::Network => "network",
QueueKind::Regular => "regular",
QueueKind::Api => "api",
}
}
}