convert hand-written enum as_str matches to strum derives workspace-wide
This commit is contained in:
parent
0d6c003fa8
commit
299add158f
14 changed files with 70 additions and 113 deletions
|
|
@ -50,6 +50,7 @@ sha2.workspace = true
|
|||
rusqlite.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
strum.workspace = true
|
||||
# Offering this hive's status to the swarm (`swarm_status`). The same crate
|
||||
# the swarm controller reads it with, and `kv` for the same reason: the
|
||||
# bucket's name and creation config belong to neither end of it alone.
|
||||
|
|
|
|||
|
|
@ -31,8 +31,9 @@ use hive_jobq::TerminalState;
|
|||
/// compose into live in the node-inventory table and surrounding sections
|
||||
/// of `docs/scheduler/coordinator.md` — this enum is deliberately not a
|
||||
/// second copy of that; each variant below gets a one-line pointer.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, strum::IntoStaticStr)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum NodeKind {
|
||||
/// The rebuild's meta-repo preamble. `relock = false` only for
|
||||
/// meta-update cascade rebuilds (re-locking would revert the bump the
|
||||
|
|
@ -201,45 +202,13 @@ impl hive_jobq_wire::WireNode for NodeKind {
|
|||
|
||||
impl NodeKind {
|
||||
/// Wire string for the node's label on the graph wire
|
||||
/// ([`hive_jobq_wire::WireNode::label`]).
|
||||
/// ([`hive_jobq_wire::WireNode::label`]) — derived
|
||||
/// (`#[strum(serialize_all = "snake_case")]`), matching the same
|
||||
/// convention the `#[serde(rename_all = "snake_case")]` tag above
|
||||
/// uses, rather than a 31-arm hand-written match kept in sync with it
|
||||
/// by hand.
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
NodeKind::MetaSync { .. } => "meta_sync",
|
||||
NodeKind::Prebuild { .. } => "prebuild",
|
||||
NodeKind::Swap { .. } => "swap",
|
||||
NodeKind::RebuildBookkeeping { .. } => "rebuild_bookkeeping",
|
||||
NodeKind::Provision { .. } => "provision",
|
||||
NodeKind::Create { .. } => "create",
|
||||
NodeKind::DestroyContainer { .. } => "destroy_container",
|
||||
NodeKind::PurgeState { .. } => "purge_state",
|
||||
NodeKind::DestroyBookkeeping { .. } => "destroy_bookkeeping",
|
||||
NodeKind::MetaLock { .. } => "meta_lock",
|
||||
NodeKind::Reconcile { .. } => "reconcile",
|
||||
NodeKind::Start { .. } => "start",
|
||||
NodeKind::Stop { .. } => "stop",
|
||||
NodeKind::StopForUpdate { .. } => "stop_for_update",
|
||||
NodeKind::Signal { .. } => "signal",
|
||||
NodeKind::Drain { .. } => "drain",
|
||||
NodeKind::PauseSignal { .. } => "pause_signal",
|
||||
NodeKind::PauseDrain { .. } => "pause_drain",
|
||||
NodeKind::WriteDropin { .. } => "write_dropin",
|
||||
NodeKind::WritePermFile { .. } => "write_perm_file",
|
||||
NodeKind::Reparent { .. } => "reparent",
|
||||
NodeKind::DeployWindow { .. } => "deploy_window",
|
||||
NodeKind::AgentWindow { .. } => "agent_window",
|
||||
NodeKind::MergeVerify { .. } => "merge_verify",
|
||||
NodeKind::DeployApply { .. } => "deploy_apply",
|
||||
NodeKind::FinalizeDeploy { .. } => "finalize_deploy",
|
||||
NodeKind::DeployTail { .. } => "deploy_tail",
|
||||
NodeKind::ResolveApproval { .. } => "resolve_approval",
|
||||
NodeKind::EmitRebuilt { .. } => "emit_rebuilt",
|
||||
NodeKind::SetWanted { .. } => "set_wanted",
|
||||
NodeKind::ForgeSweep => "forge_sweep",
|
||||
NodeKind::MatrixSweep => "matrix_sweep",
|
||||
NodeKind::WebhookRegister => "webhook_register",
|
||||
NodeKind::KnowledgePull => "knowledge_pull",
|
||||
NodeKind::WantedPull => "wanted_pull",
|
||||
}
|
||||
self.into()
|
||||
}
|
||||
|
||||
/// The agent this node targets, or `""` for agentless kinds
|
||||
|
|
|
|||
|
|
@ -90,8 +90,9 @@ const MIGRATIONS: &[Migration] = &[Migration {
|
|||
|
||||
/// Status of a finished build attempt. Stored as the literal string in
|
||||
/// the `status` column; `NULL` while the attempt is still in progress.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, strum::IntoStaticStr)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum BuildStatus {
|
||||
/// Child exited with success.
|
||||
Ok,
|
||||
|
|
@ -101,10 +102,7 @@ pub enum BuildStatus {
|
|||
|
||||
impl BuildStatus {
|
||||
fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Ok => "ok",
|
||||
Self::Fail => "fail",
|
||||
}
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ CREATE TABLE IF NOT EXISTS agent_power (
|
|||
";
|
||||
|
||||
/// Per-agent power intent.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::IntoStaticStr, strum::EnumString)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum Wanted {
|
||||
Up,
|
||||
Offline,
|
||||
|
|
@ -38,18 +39,14 @@ pub enum Wanted {
|
|||
|
||||
impl Wanted {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Wanted::Up => "up",
|
||||
Wanted::Offline => "offline",
|
||||
}
|
||||
self.into()
|
||||
}
|
||||
|
||||
/// Derived (`strum::EnumString`, the same `snake_case` convention
|
||||
/// `as_str` uses) rather than a hand-written match kept in sync with
|
||||
/// it by hand.
|
||||
fn parse(s: &str) -> Option<Self> {
|
||||
match s {
|
||||
"up" => Some(Wanted::Up),
|
||||
"offline" => Some(Wanted::Offline),
|
||||
_ => None,
|
||||
}
|
||||
s.parse().ok()
|
||||
}
|
||||
|
||||
/// Seed value from an observed running state (first boot after
|
||||
|
|
|
|||
Loading…
Reference in a new issue