Skip to main content

supercode_interchange/orchestration/
fire.rs

1//! Fires: one execution of a job (§2.6; Hermes `cron/executions.db`).
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::ontology::Residue;
7
8/// A fire's status. `unknown` is Hermes's own word for a fire whose scheduler
9/// restarted under it; `completed` ⇄ `succeeded` on the codec boundary and
10/// `timeout` writes back as `failed`.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
12#[serde(rename_all = "snake_case")]
13pub enum FireStatus {
14    /// Claimed, not yet started.
15    Claimed,
16    /// Running (read from Hermes; never written by us).
17    Running,
18    /// Finished with a result.
19    Succeeded,
20    /// Finished with an error.
21    Failed,
22    /// The session ended without a result.
23    Timeout,
24    /// The scheduler restarted under it.
25    Unknown,
26}
27
28impl FireStatus {
29    /// Hermes's `executions.status` word.
30    pub fn hermes_word(self) -> &'static str {
31        match self {
32            Self::Claimed => "claimed",
33            Self::Running => "running",
34            Self::Succeeded => "completed",
35            Self::Failed | Self::Timeout => "failed",
36            Self::Unknown => "unknown",
37        }
38    }
39
40    /// The status for a Hermes `executions.status` word.
41    pub fn from_hermes_word(word: &str) -> Option<Self> {
42        Some(match word {
43            "claimed" => Self::Claimed,
44            "running" => Self::Running,
45            "completed" => Self::Succeeded,
46            "failed" => Self::Failed,
47            "unknown" => Self::Unknown,
48            _ => return None,
49        })
50    }
51}
52
53/// One fire.
54#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
55pub struct Fire {
56    /// The fire id, which is also its session name `cron_<job_id>_<ts>`.
57    pub id: String,
58    /// The job.
59    pub job_id: String,
60    /// The session it opened, when known.
61    #[serde(default)]
62    pub session_id: Option<String>,
63    /// Status.
64    pub status: FireStatus,
65    /// Claim instant.
66    pub claimed_at: String,
67    /// Start instant.
68    #[serde(default)]
69    pub started_at: Option<String>,
70    /// Finish instant.
71    #[serde(default)]
72    pub finished_at: Option<String>,
73    /// The error, on failure.
74    #[serde(default)]
75    pub error: Option<String>,
76    /// The delivery this fire produced, if any.
77    #[serde(default)]
78    pub obligation_id: Option<String>,
79    /// Ledger columns the record does not model (`source`, `pid`, …), verbatim.
80    #[serde(default)]
81    pub residue: Residue,
82}