refactor: parse systemd state strings at the bus boundary
This commit is contained in:
1 parent
9812a85443
commit
741e6d13bb
2 files changed
+24
-30
No files matched your search
@@ -10,20 +10,6 @@ pub enum ActiveState {
|
|||||||
Failed,
|
Failed,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveState {
|
|
||||||
#[must_use]
|
|
||||||
pub fn parse(raw: &str) -> Self {
|
|
||||||
match raw {
|
|
||||||
"activating" => Self::Activating,
|
|
||||||
"active" => Self::Active,
|
|
||||||
"deactivating" => Self::Deactivating,
|
|
||||||
"reloading" => Self::Reloading,
|
|
||||||
"failed" => Self::Failed,
|
|
||||||
_ => Self::Inactive,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum JobResult {
|
pub enum JobResult {
|
||||||
Done,
|
Done,
|
||||||
@@ -34,20 +20,6 @@ pub enum JobResult {
|
|||||||
Dependency,
|
Dependency,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JobResult {
|
|
||||||
#[must_use]
|
|
||||||
pub fn parse(raw: &str) -> Self {
|
|
||||||
match raw {
|
|
||||||
"done" => Self::Done,
|
|
||||||
"skipped" => Self::Skipped,
|
|
||||||
"canceled" => Self::Canceled,
|
|
||||||
"timeout" => Self::Timeout,
|
|
||||||
"dependency" => Self::Dependency,
|
|
||||||
_ => Self::Failed,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct UnitFacts {
|
pub struct UnitFacts {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ fn parse_job_signal(message: &Message, member: &str) -> Option<Signal> {
|
|||||||
message.read4().ok()?;
|
message.read4().ok()?;
|
||||||
Some(Signal::JobRemoved {
|
Some(Signal::JobRemoved {
|
||||||
id,
|
id,
|
||||||
result: JobResult::parse(&result),
|
result: job_result_from_bus(&result),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
@@ -329,9 +329,31 @@ fn activity_from(properties: &PropMap) -> Activity {
|
|||||||
state: properties
|
state: properties
|
||||||
.get("ActiveState")
|
.get("ActiveState")
|
||||||
.and_then(|value| value.0.as_str())
|
.and_then(|value| value.0.as_str())
|
||||||
.map(ActiveState::parse),
|
.map(active_state_from_bus),
|
||||||
inactive_exit: monotonic("InactiveExitTimestampMonotonic"),
|
inactive_exit: monotonic("InactiveExitTimestampMonotonic"),
|
||||||
active_enter: monotonic("ActiveEnterTimestampMonotonic"),
|
active_enter: monotonic("ActiveEnterTimestampMonotonic"),
|
||||||
active_exit: monotonic("ActiveExitTimestampMonotonic"),
|
active_exit: monotonic("ActiveExitTimestampMonotonic"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn active_state_from_bus(raw: &str) -> ActiveState {
|
||||||
|
match raw {
|
||||||
|
"activating" => ActiveState::Activating,
|
||||||
|
"active" => ActiveState::Active,
|
||||||
|
"deactivating" => ActiveState::Deactivating,
|
||||||
|
"reloading" => ActiveState::Reloading,
|
||||||
|
"failed" => ActiveState::Failed,
|
||||||
|
_ => ActiveState::Inactive,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn job_result_from_bus(raw: &str) -> JobResult {
|
||||||
|
match raw {
|
||||||
|
"done" => JobResult::Done,
|
||||||
|
"skipped" => JobResult::Skipped,
|
||||||
|
"canceled" => JobResult::Canceled,
|
||||||
|
"timeout" => JobResult::Timeout,
|
||||||
|
"dependency" => JobResult::Dependency,
|
||||||
|
_ => JobResult::Failed,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user