ntex_server/status.rs
1/// Server status.
2///
3/// Returned by [`Server::status`](crate::Server::status) and
4/// [`Server::status_changed`](crate::Server::status_changed). The server
5/// accepts new items, and network listeners accept connections, only while
6/// the status is [`Ready`](ServerStatus::Ready).
7#[non_exhaustive]
8#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
9pub enum ServerStatus {
10 /// No worker has become available yet.
11 Starting,
12 /// Workers are available and the server accepts new items.
13 Ready,
14 /// The server has been paused with [`Server::pause`](crate::Server::pause).
15 ///
16 /// The server stays paused until [`Server::resume`](crate::Server::resume)
17 /// is called, even if workers restart or become available.
18 Paused,
19 /// No worker is available, e.g. all workers are restarting or not ready.
20 ///
21 /// The server becomes ready again once a worker is available.
22 Unavailable,
23 /// The server is stopping its workers.
24 Stopping,
25 /// The server has stopped. This status is final.
26 Stopped,
27}
28
29impl ServerStatus {
30 pub(crate) const fn from_u8(val: u8) -> Self {
31 match val {
32 0 => ServerStatus::Starting,
33 1 => ServerStatus::Ready,
34 2 => ServerStatus::Paused,
35 3 => ServerStatus::Unavailable,
36 4 => ServerStatus::Stopping,
37 _ => ServerStatus::Stopped,
38 }
39 }
40
41 pub(crate) const fn as_u8(self) -> u8 {
42 match self {
43 ServerStatus::Starting => 0,
44 ServerStatus::Ready => 1,
45 ServerStatus::Paused => 2,
46 ServerStatus::Unavailable => 3,
47 ServerStatus::Stopping => 4,
48 ServerStatus::Stopped => 5,
49 }
50 }
51}