1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateTaskExecutionError {
20 UnknownValue(serde_json::Value),
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum GetTaskExecutionError {
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ListTaskExecutionsError {
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum UpdateTaskExecutionStatusError {
41 UnknownValue(serde_json::Value),
42}
43
44pub async fn create_task_execution(
46 configuration: &configuration::Configuration,
47 x_workflow_executor_token: &str,
48 pipeline_run_uuid: &str,
49 req_create_task_execution: models::ReqCreateTaskExecution,
50) -> Result<models::RespResourceUrl, Error<CreateTaskExecutionError>> {
51 let p_header_x_workflow_executor_token = x_workflow_executor_token;
53 let p_path_pipeline_run_uuid = pipeline_run_uuid;
54 let p_body_req_create_task_execution = req_create_task_execution;
55
56 let uri_str = format!(
57 "{}/v3/workflows/executor/runs/{pipeline_run_uuid}/executions",
58 configuration.base_path,
59 pipeline_run_uuid = crate::apis::urlencode(p_path_pipeline_run_uuid)
60 );
61 let mut req_builder = configuration
62 .client
63 .request(reqwest::Method::POST, &uri_str);
64
65 if let Some(ref user_agent) = configuration.user_agent {
66 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
67 }
68 req_builder = req_builder.header(
69 "X-WORKFLOW-EXECUTOR-TOKEN",
70 p_header_x_workflow_executor_token.to_string(),
71 );
72 if let Some(ref apikey) = configuration.api_key {
73 let key = apikey.key.clone();
74 let value = match apikey.prefix {
75 Some(ref prefix) => format!("{} {}", prefix, key),
76 None => key,
77 };
78 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
79 };
80 req_builder = req_builder.json(&p_body_req_create_task_execution);
81
82 let req = req_builder.build()?;
83 let resp = configuration.client.execute(req).await?;
84
85 let status = resp.status();
86 let content_type = resp
87 .headers()
88 .get("content-type")
89 .and_then(|v| v.to_str().ok())
90 .unwrap_or("application/octet-stream");
91 let content_type = super::ContentType::from(content_type);
92
93 if !status.is_client_error() && !status.is_server_error() {
94 let content = resp.text().await?;
95 match content_type {
96 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
98 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespResourceUrl`")))),
99 }
100 } else {
101 let content = resp.text().await?;
102 let entity: Option<CreateTaskExecutionError> = serde_json::from_str(&content).ok();
103 Err(Error::ResponseError(ResponseContent {
104 status,
105 content,
106 entity,
107 }))
108 }
109}
110
111pub async fn get_task_execution(
113 configuration: &configuration::Configuration,
114 group_id: &str,
115 pipeline_id: &str,
116 pipeline_run_uuid: &str,
117 task_execution_uuid: &str,
118) -> Result<models::RespTaskExecution, Error<GetTaskExecutionError>> {
119 let p_path_group_id = group_id;
121 let p_path_pipeline_id = pipeline_id;
122 let p_path_pipeline_run_uuid = pipeline_run_uuid;
123 let p_path_task_execution_uuid = task_execution_uuid;
124
125 let uri_str = format!("{}/v3/workflows/groups/{group_id}/pipelines/{pipeline_id}/runs/{pipeline_run_uuid}/executions/{task_execution_uuid}", configuration.base_path, group_id=crate::apis::urlencode(p_path_group_id), pipeline_id=crate::apis::urlencode(p_path_pipeline_id), pipeline_run_uuid=crate::apis::urlencode(p_path_pipeline_run_uuid), task_execution_uuid=crate::apis::urlencode(p_path_task_execution_uuid));
126 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
127
128 if let Some(ref user_agent) = configuration.user_agent {
129 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130 }
131 if let Some(ref apikey) = configuration.api_key {
132 let key = apikey.key.clone();
133 let value = match apikey.prefix {
134 Some(ref prefix) => format!("{} {}", prefix, key),
135 None => key,
136 };
137 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
138 };
139
140 let req = req_builder.build()?;
141 let resp = configuration.client.execute(req).await?;
142
143 let status = resp.status();
144 let content_type = resp
145 .headers()
146 .get("content-type")
147 .and_then(|v| v.to_str().ok())
148 .unwrap_or("application/octet-stream");
149 let content_type = super::ContentType::from(content_type);
150
151 if !status.is_client_error() && !status.is_server_error() {
152 let content = resp.text().await?;
153 match content_type {
154 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
155 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespTaskExecution`"))),
156 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespTaskExecution`")))),
157 }
158 } else {
159 let content = resp.text().await?;
160 let entity: Option<GetTaskExecutionError> = serde_json::from_str(&content).ok();
161 Err(Error::ResponseError(ResponseContent {
162 status,
163 content,
164 entity,
165 }))
166 }
167}
168
169pub async fn list_task_executions(
171 configuration: &configuration::Configuration,
172 group_id: &str,
173 pipeline_id: &str,
174 pipeline_run_uuid: &str,
175) -> Result<models::RespTaskExecutionList, Error<ListTaskExecutionsError>> {
176 let p_path_group_id = group_id;
178 let p_path_pipeline_id = pipeline_id;
179 let p_path_pipeline_run_uuid = pipeline_run_uuid;
180
181 let uri_str = format!("{}/v3/workflows/groups/{group_id}/pipelines/{pipeline_id}/runs/{pipeline_run_uuid}/executions", configuration.base_path, group_id=crate::apis::urlencode(p_path_group_id), pipeline_id=crate::apis::urlencode(p_path_pipeline_id), pipeline_run_uuid=crate::apis::urlencode(p_path_pipeline_run_uuid));
182 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
183
184 if let Some(ref user_agent) = configuration.user_agent {
185 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
186 }
187 if let Some(ref apikey) = configuration.api_key {
188 let key = apikey.key.clone();
189 let value = match apikey.prefix {
190 Some(ref prefix) => format!("{} {}", prefix, key),
191 None => key,
192 };
193 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
194 };
195
196 let req = req_builder.build()?;
197 let resp = configuration.client.execute(req).await?;
198
199 let status = resp.status();
200 let content_type = resp
201 .headers()
202 .get("content-type")
203 .and_then(|v| v.to_str().ok())
204 .unwrap_or("application/octet-stream");
205 let content_type = super::ContentType::from(content_type);
206
207 if !status.is_client_error() && !status.is_server_error() {
208 let content = resp.text().await?;
209 match content_type {
210 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespTaskExecutionList`"))),
212 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespTaskExecutionList`")))),
213 }
214 } else {
215 let content = resp.text().await?;
216 let entity: Option<ListTaskExecutionsError> = serde_json::from_str(&content).ok();
217 Err(Error::ResponseError(ResponseContent {
218 status,
219 content,
220 entity,
221 }))
222 }
223}
224
225pub async fn update_task_execution_status(
227 configuration: &configuration::Configuration,
228 x_workflow_executor_token: &str,
229 task_execution_uuid: &str,
230 status: models::EnumRunStatus,
231 req_patch_task_execution: Option<models::ReqPatchTaskExecution>,
232) -> Result<models::RespString, Error<UpdateTaskExecutionStatusError>> {
233 let p_header_x_workflow_executor_token = x_workflow_executor_token;
235 let p_path_task_execution_uuid = task_execution_uuid;
236 let p_path_status = status;
237 let p_body_req_patch_task_execution = req_patch_task_execution;
238
239 let uri_str = format!(
240 "{}/v3/workflows/executor/executions/{task_execution_uuid}/{status}",
241 configuration.base_path,
242 task_execution_uuid = crate::apis::urlencode(p_path_task_execution_uuid),
243 status = p_path_status
244 );
245 let mut req_builder = configuration
246 .client
247 .request(reqwest::Method::PATCH, &uri_str);
248
249 if let Some(ref user_agent) = configuration.user_agent {
250 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
251 }
252 req_builder = req_builder.header(
253 "X-WORKFLOW-EXECUTOR-TOKEN",
254 p_header_x_workflow_executor_token.to_string(),
255 );
256 if let Some(ref apikey) = configuration.api_key {
257 let key = apikey.key.clone();
258 let value = match apikey.prefix {
259 Some(ref prefix) => format!("{} {}", prefix, key),
260 None => key,
261 };
262 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
263 };
264 req_builder = req_builder.json(&p_body_req_patch_task_execution);
265
266 let req = req_builder.build()?;
267 let resp = configuration.client.execute(req).await?;
268
269 let status = resp.status();
270 let content_type = resp
271 .headers()
272 .get("content-type")
273 .and_then(|v| v.to_str().ok())
274 .unwrap_or("application/octet-stream");
275 let content_type = super::ContentType::from(content_type);
276
277 if !status.is_client_error() && !status.is_server_error() {
278 let content = resp.text().await?;
279 match content_type {
280 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
281 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespString`"))),
282 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespString`")))),
283 }
284 } else {
285 let content = resp.text().await?;
286 let entity: Option<UpdateTaskExecutionStatusError> = serde_json::from_str(&content).ok();
287 Err(Error::ResponseError(ResponseContent {
288 status,
289 content,
290 entity,
291 }))
292 }
293}