Skip to main content

clia_influxdb2/models/
task.rs

1//! Task
2
3use serde::{Deserialize, Serialize};
4
5/// Task status
6#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
7pub enum TaskStatusType {
8    /// Active task status
9    #[serde(rename = "active")]
10    Active,
11    /// Inactive task status
12    #[serde(rename = "inactive")]
13    Inactive,
14}
15
16/// Task schema
17#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19pub struct Task {
20    /// Task ID
21    pub id: String,
22    /// Task name
23    pub name: String,
24    /// The ID of the organization that owns this task
25    #[serde(rename = "orgID")]
26    pub org_id: String,
27    /// The FLUX script to run this task
28    pub flux: String,
29    /// The ID of the user who owns this task
30    #[serde(rename = "ownerID")]
31    pub owner_id: Option<String>,
32    /// The name of the organization that owns this task
33    pub org: Option<String>,
34    /// Task status
35    pub status: Option<TaskStatusType>,
36    /// The type of task, this can be used for filtering tasks on list actions.
37    #[serde(rename = "type")]
38    pub type_: Option<String>,
39    /// The ID of the authorization used when this task communicates with the
40    /// query engine
41    #[serde(rename = "authorizationID")]
42    pub authorization_id: Option<String>,
43    /// An optional description of the task
44    pub description: Option<String>,
45    /// A task repetition schedule in the form '* * * * * *', parsed from Flux
46    pub cron: Option<String>,
47    /// A simple task repetition schedule, parsed from Flux
48    pub every: Option<String>,
49    /// Task error on last run
50    pub last_run_error: Option<String>,
51    /// Status of task on last run
52    pub last_run_status: Option<String>,
53    /// Timestamp of latest scheduled, completed run, RFC3339
54    pub latest_completed: Option<String>,
55    /// Duration to delay after the schedule, before executing the task;
56    /// parsed from flux
57    pub offset: Option<String>,
58    /// Links
59    pub links: Option<TaskLinks>,
60    /// Task Labels
61    #[serde(default, skip_serializing_if = "Vec::is_empty")]
62    pub labels: Vec<crate::models::Label>,
63    /// Task created timestamp
64    pub created_at: Option<String>,
65    /// Task updated timestamp
66    pub updated_at: Option<String>,
67}
68
69/// Task Links
70#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
71pub struct TaskLinks {
72    /// Link to self
73    #[serde(rename = "self", skip_serializing_if = "Option::is_none")]
74    pub self_: Option<String>,
75    /// Link to labels
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub labels: Option<String>,
78    /// Link to logs
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub logs: Option<String>,
81    /// Link to members
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub members: Option<String>,
84    /// Link to owners
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub owners: Option<String>,
87    /// Link to runs
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub runs: Option<String>,
90}
91
92/// Tasks
93#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
94pub struct Tasks {
95    /// Links
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub links: Option<crate::models::Links>,
98    /// List of tasks
99    #[serde(default, skip_serializing_if = "Vec::is_empty")]
100    pub tasks: Vec<Task>,
101}
102
103#[cfg(test)]
104mod tests {
105    use super::*;
106
107    #[test]
108    fn serialize_task_status_type() {
109        let v = serde_json::to_string(&TaskStatusType::Active).unwrap();
110        assert_eq!(v, "\"active\"");
111        let v = serde_json::to_string(&TaskStatusType::Inactive).unwrap();
112        assert_eq!(v, "\"inactive\"");
113    }
114}