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
//! Tasks API: A task is a container running on a swarm. It is the atomic scheduling unit of swarm. Swarm mode must be enabled for these endpoints to work.
use bollard_stubs::models::Task;
use bytes::Bytes;
use futures_core::Stream;
use http_body_util::Full;
use crate::{container::LogOutput, docker::BodyType, errors::Error, Docker};
use http::{request::Builder, Method};
impl Docker {
/// ---
///
/// # List Tasks
///
/// # Arguments
///
/// - Optional [List Tasks Options](crate::query_parameters::ListTasksOptions) struct.
///
/// # Returns
///
/// - A vector of [Task](Task) struct, wrapped in a
/// Future.
///
/// # Examples
///
/// ```rust
/// # use bollard::Docker;
/// # let docker = Docker::connect_with_http_defaults().unwrap();
///
/// use bollard::query_parameters::ListTasksOptionsBuilder;
///
/// use std::collections::HashMap;
///
/// let mut filters = HashMap::new();
/// filters.insert("label", vec!["my-task-label"]);
///
/// let options = ListTasksOptionsBuilder::default()
/// .filters(&filters)
/// .build();
///
/// docker.list_tasks(Some(options));
/// ```
pub async fn list_tasks(
&self,
options: Option<crate::query_parameters::ListTasksOptions>,
) -> Result<Vec<Task>, Error> {
let url = "/tasks";
let req = self.build_request(
url,
Builder::new().method(Method::GET),
options,
Ok(BodyType::Left(Full::new(Bytes::new()))),
);
self.process_into_value(req).await
}
/// ---
///
/// # Inspect a Task
///
/// # Arguments
///
/// - Task id as a string slice.
///
/// # Returns
///
/// - A [Models](Task) struct, wrapped in a Future.
///
/// # Examples
///
/// ```rust
/// # use bollard::Docker;
/// # let docker = Docker::connect_with_http_defaults().unwrap();
///
/// docker.inspect_task("my_task_id");
/// ```
pub async fn inspect_task(&self, task_id: &str) -> Result<Task, Error> {
let url = format!("/tasks/{task_id}");
let req = self.build_request(
&url,
Builder::new().method(Method::GET),
None::<String>,
Ok(BodyType::Left(Full::new(Bytes::new()))),
);
self.process_into_value(req).await
}
/// ---
///
/// # Get Task Logs
///
/// Get `stdout` and `stderr` logs from a task.
///
/// # Arguments
///
/// - Task id as a string slice.
/// - Optional [Logs Options](crate::query_parameters::LogsOptions) struct.
///
/// # Returns
///
/// - A Stream of [Log Output](LogOutput) results.
///
/// # Examples
///
/// ```rust
/// # use bollard::Docker;
/// # let docker = Docker::connect_with_http_defaults().unwrap();
/// use bollard::query_parameters::LogsOptionsBuilder;
///
/// let options = LogsOptionsBuilder::default()
/// .stdout(true)
/// .build();
///
/// docker.task_logs("my-task-id", Some(options));
/// ```
pub fn task_logs(
&self,
task_id: &str,
options: Option<impl Into<crate::query_parameters::LogsOptions>>,
) -> impl Stream<Item = Result<LogOutput, Error>> {
let url = format!("/tasks/{task_id}/logs");
let req = self.build_request(
&url,
Builder::new().method(Method::GET),
options.map(Into::into),
Ok(BodyType::Left(Full::new(Bytes::new()))),
);
self.process_into_stream_string(req)
}
}