selectel_mks/task/
schemas.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4/// Status represents a enum with various task statuses.
5#[derive(Debug, Deserialize, Serialize)]
6#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
7pub enum Status {
8    InProgress,
9    Done,
10    Error,
11    Unknown,
12}
13
14impl std::fmt::Display for Status {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match *self {
17            Status::InProgress => "IN_PROGRESS".fmt(f),
18            Status::Done => "DONE".fmt(f),
19            Status::Error => "ERROR".fmt(f),
20            Status::Unknown => "UNKNOWN".fmt(f),
21        }
22    }
23}
24
25/// Type represents a enum with various task types.
26#[derive(Debug, Deserialize, Serialize)]
27#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
28pub enum Type {
29    CreateCluster,
30    DeleteCluster,
31    RotateCerts,
32    NodeGroupResize,
33    NodeReinstall,
34    ClusterResize,
35    UpgradePatchVersion,
36    UpgradeMinorVersion,
37    UpdateNodegroupLabels,
38    UpgradeMastersConfiguration,
39    UpgradeClusterConfiguration,
40    Unknown,
41}
42
43impl std::fmt::Display for Type {
44    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        match *self {
46            Type::CreateCluster => "CREATE_CLUSTER".fmt(f),
47            Type::DeleteCluster => "DELETE_CLUSTER".fmt(f),
48            Type::RotateCerts => "ROTATE_CERTS".fmt(f),
49            Type::NodeGroupResize => "NODE_GROUP_RESIZE".fmt(f),
50            Type::NodeReinstall => "NODE_REINSTALL".fmt(f),
51            Type::ClusterResize => "CLUSTER_RESIZE".fmt(f),
52            Type::UpgradePatchVersion => "UPGRADE_PATCH_VERSION".fmt(f),
53            Type::UpgradeMinorVersion => "UPGRADE_MINOR_VERSION".fmt(f),
54            Type::UpdateNodegroupLabels => "UPDATE_NODEGROUP_LABELS".fmt(f),
55            Type::UpgradeMastersConfiguration => "UPGRADE_MASTERS_CONFIGURATION".fmt(f),
56            Type::UpgradeClusterConfiguration => "UPGRADE_CLUSTER_CONFIGURATION".fmt(f),
57            Type::Unknown => "UNKNOWN".fmt(f),
58        }
59    }
60}
61
62/// Task represents a deserialized task body from an API response.
63#[derive(Debug, Deserialize, Serialize)]
64pub struct Task {
65    /// Task identifier.
66    pub id: String,
67
68    /// Timestamp in UTC timezone of when the task has been started.
69    pub started_at: DateTime<Utc>,
70
71    /// Timestamp in UTC timezone of when the task has been updated.
72    pub updated_at: Option<DateTime<Utc>>,
73
74    /// Cluster identifier.
75    pub cluster_id: String,
76
77    /// Current task status.
78    pub status: Status,
79
80    /// Task type.
81    #[serde(rename = "type")]
82    pub task_type: Type,
83}
84
85/// TaskRoot represents a root of a deserialized task.
86#[derive(Debug, Deserialize, Serialize)]
87pub struct TaskRoot {
88    pub task: Task,
89}
90
91/// ListRoot represents a root of a list with deserialized tasks.
92#[derive(Debug, Deserialize, Serialize)]
93pub struct ListRoot {
94    pub tasks: Vec<Task>,
95}