Skip to main content

comindly_api/
jobs.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4#[serde(rename_all = "lowercase")]
5pub enum Status {
6    Queued,
7    Running,
8    Succeeded,
9    Failed,
10    Cancelled,
11    /// The process stopped while it ran; what was saved stays, and it can run again.
12    Interrupted,
13    /// Stopped by a restart; it continues by itself once a server is back.
14    Paused,
15}
16
17impl Status {
18    pub fn finished(self) -> bool {
19        !matches!(self, Status::Queued | Status::Running | Status::Paused)
20    }
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct JobRecord {
25    pub id: String,
26    pub kind: String,
27    pub started_by: Option<String>,
28    pub status: Status,
29    pub created: String,
30    #[serde(default)]
31    pub started: Option<String>,
32    pub finished: Option<String>,
33    pub error: Option<String>,
34    /// The request that started it, as in its `X-Request-Id`.
35    #[serde(default, skip_serializing_if = "Option::is_none")]
36    pub request_id: Option<String>,
37    /// What to run again after a restart; a job without it cannot continue.
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub request: Option<serde_json::Value>,
40    /// The running job's last sign of life, so a starting server leaves a live one alone.
41    #[serde(default, skip_serializing_if = "Option::is_none")]
42    pub beat: Option<String>,
43}