1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#![cfg(feature = "swarm")]
use crate::Result;
impl_api_ty!(Task => id: I);
impl<'docker> Task<'docker> {
impl_api_ep! { task: Task, resp
Inspect -> format!("/tasks/{}", task.id)
Logs -> format!("/tasks/{}/logs", task.id)
}
}
impl<'docker> Tasks<'docker> {
impl_api_ep! { task: Task, resp
List -> "/tasks"
}
}
pub mod data {
use crate::api::{Labels, ObjectVersion};
use serde::{Deserialize, Serialize};
#[cfg(feature = "chrono")]
use chrono::{DateTime, Utc};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct TaskInfo {
#[serde(rename = "ID")]
pub id: String,
pub version: ObjectVersion,
#[cfg(feature = "chrono")]
pub created_at: DateTime<Utc>,
#[cfg(not(feature = "chrono"))]
pub created_at: String,
#[cfg(feature = "chrono")]
pub updated_at: DateTime<Utc>,
#[cfg(not(feature = "chrono"))]
pub updated_at: String,
pub name: String,
pub labels: Labels,
pub spec: TaskSpec,
pub slot: isize,
#[serde(rename = "NodeID")]
pub node_id: String,
pub status: Status,
pub desired_state: TaskState,
pub job_iteration: ObjectVersion,
}
pub type TaskState = String;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct Status {
#[cfg(feature = "chrono")]
pub timestamp: DateTime<Utc>,
#[cfg(not(feature = "chrono"))]
pub timestamp: String,
pub state: TaskState,
pub message: String,
pub err: String,
pub container_status: ContainerStatus,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ContainerStatus {
#[serde(rename = "ContainerID")]
pub container_id: String,
#[serde(rename = "PID")]
pub pid: isize,
pub exit_code: isize,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct TaskSpec {}
}
pub use data::*;
pub mod opts {
use crate::api::Filter;
impl_url_opts_builder!(TaskList);
#[derive(Clone, Copy, Debug)]
pub enum State {
Running,
Shutdown,
Accepted,
}
impl AsRef<str> for State {
fn as_ref(&self) -> &str {
match &self {
Self::Running => "running",
Self::Shutdown => "shutdown",
Self::Accepted => "accepted",
}
}
}
pub enum TaskFilter {
DesiredState(State),
Id(String),
LabelKey(String),
LabelKeyVal(String, String),
Name(String),
Node(String),
Service(String),
}
impl Filter for TaskFilter {
fn query_key_val(&self) -> (&'static str, String) {
use TaskFilter::*;
match &self {
DesiredState(state) => ("desired-state", state.as_ref().to_string()),
Id(id) => ("id", id.to_owned()),
LabelKey(key) => ("label", key.to_owned()),
LabelKeyVal(key, val) => ("label", format!("{}={}", key, val)),
Name(name) => ("name", name.to_owned()),
Node(node) => ("node", node.to_owned()),
Service(service) => ("service", service.to_owned()),
}
}
}
impl TaskListOptsBuilder {
impl_filter_func!(TaskFilter);
}
}
pub use opts::*;