1use chrono::{DateTime, Utc};
2use futures::Stream;
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5use std::fmt;
6use std::pin::Pin;
7
8use crate::error::Result;
9
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12#[serde(rename_all = "PascalCase")]
13pub enum ServiceState {
14 Unknown,
16 Blocked,
18 Spawned,
20 Running,
22 Success,
24 Error,
26 TestFailure,
28}
29
30impl fmt::Display for ServiceState {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 ServiceState::Unknown => write!(f, "Unknown"),
34 ServiceState::Blocked => write!(f, "Blocked"),
35 ServiceState::Spawned => write!(f, "Spawned"),
36 ServiceState::Running => write!(f, "Running"),
37 ServiceState::Success => write!(f, "Success"),
38 ServiceState::Error => write!(f, "Error"),
39 ServiceState::TestFailure => write!(f, "TestFailure"),
40 }
41 }
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
46#[serde(rename_all = "PascalCase")]
47pub enum ServiceTarget {
48 Up,
50 Down,
52}
53
54impl fmt::Display for ServiceTarget {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 match self {
57 ServiceTarget::Up => write!(f, "Up"),
58 ServiceTarget::Down => write!(f, "Down"),
59 }
60 }
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct ServiceStatus {
66 pub name: String,
68 pub pid: u32,
70 pub state: ServiceState,
72 pub target: ServiceTarget,
74 pub after: HashMap<String, String>,
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct LogEntry {
81 pub timestamp: DateTime<Utc>,
83 pub service: String,
85 pub message: String,
87}
88
89pub struct LogStream {
91 pub(crate) inner: Pin<Box<dyn Stream<Item = Result<LogEntry>> + Send>>,
93}
94
95impl Stream for LogStream {
96 type Item = Result<LogEntry>;
97
98 fn poll_next(
99 mut self: Pin<&mut Self>,
100 cx: &mut std::task::Context<'_>,
101 ) -> std::task::Poll<Option<Self::Item>> {
102 Pin::new(&mut self.inner).poll_next(cx)
103 }
104}
105
106#[derive(Debug, Clone, Deserialize)]
108pub(crate) struct Response {
109 pub state: ResponseState,
111 pub body: serde_json::Value,
113}
114
115#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
117#[serde(rename_all = "lowercase")]
118pub(crate) enum ResponseState {
119 Ok,
121 Error,
123}