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
use ya_client_model::activity::{ExeScriptCommandResult, ExeScriptRequest, ACTIVITY_API_PATH};
use crate::{web::default_on_timeout, web::WebClient, web::WebInterface, Result};
#[derive(Clone)]
pub struct ActivityRequestorControlApi {
client: WebClient,
}
impl WebInterface for ActivityRequestorControlApi {
const API_URL_ENV_VAR: &'static str = crate::activity::ACTIVITY_URL_ENV_VAR;
const API_SUFFIX: &'static str = ACTIVITY_API_PATH;
fn from_client(client: WebClient) -> Self {
ActivityRequestorControlApi { client }
}
}
impl ActivityRequestorControlApi {
pub async fn create_activity(&self, agreement_id: &str) -> Result<String> {
self.client
.post("activity")
.send_json(&agreement_id)
.json()
.await
}
pub async fn destroy_activity(&self, activity_id: &str) -> Result<()> {
let uri = url_format!("activity/{activity_id}", activity_id);
self.client.delete(&uri).send().json().await?;
Ok(())
}
pub async fn exec(&self, script: ExeScriptRequest, activity_id: &str) -> Result<String> {
let uri = url_format!("activity/{activity_id}/exec", activity_id);
self.client.post(&uri).send_json(&script).json().await
}
#[rustfmt::skip]
pub async fn get_exec_batch_results(
&self,
activity_id: &str,
batch_id: &str,
#[allow(non_snake_case)]
timeout: Option<f32>,
command_index: Option<usize>,
) -> Result<Vec<ExeScriptCommandResult>> {
let uri = url_format!(
"activity/{activity_id}/exec/{batch_id}",
activity_id,
batch_id,
#[query] timeout,
#[query] command_index,
);
self.client.get(&uri).send().json().await.or_else(default_on_timeout)
}
}