708 lines
22 KiB
Plaintext
708 lines
22 KiB
Plaintext
#[allow(unused_imports)]
|
|
use progenitor_client::{encode_path, RequestBuilderExt};
|
|
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
|
#[allow(unused_imports)]
|
|
use reqwest::header::{HeaderMap, HeaderValue};
|
|
pub mod types {
|
|
use serde::{Deserialize, Serialize};
|
|
#[allow(unused_imports)]
|
|
use std::convert::TryFrom;
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct Task {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub output_rules: Vec<String>,
|
|
pub script: String,
|
|
pub state: String,
|
|
}
|
|
|
|
impl From<&Task> for Task {
|
|
fn from(value: &Task) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct TaskEvent {
|
|
pub payload: String,
|
|
pub seq: u32,
|
|
pub stream: String,
|
|
pub time: chrono::DateTime<chrono::offset::Utc>,
|
|
}
|
|
|
|
impl From<&TaskEvent> for TaskEvent {
|
|
fn from(value: &TaskEvent) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct TaskOutput {
|
|
pub id: String,
|
|
pub path: String,
|
|
pub size: u64,
|
|
}
|
|
|
|
impl From<&TaskOutput> for TaskOutput {
|
|
fn from(value: &TaskOutput) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct TaskSubmit {
|
|
pub name: String,
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
pub output_rules: Vec<String>,
|
|
pub script: String,
|
|
}
|
|
|
|
impl From<&TaskSubmit> for TaskSubmit {
|
|
fn from(value: &TaskSubmit) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct TaskSubmitResult {
|
|
pub id: String,
|
|
}
|
|
|
|
impl From<&TaskSubmitResult> for TaskSubmitResult {
|
|
fn from(value: &TaskSubmitResult) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct UploadedChunk {
|
|
pub id: String,
|
|
}
|
|
|
|
impl From<&UploadedChunk> for UploadedChunk {
|
|
fn from(value: &UploadedChunk) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct UserCreate {
|
|
pub name: String,
|
|
}
|
|
|
|
impl From<&UserCreate> for UserCreate {
|
|
fn from(value: &UserCreate) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct UserCreateResult {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub token: String,
|
|
}
|
|
|
|
impl From<&UserCreateResult> for UserCreateResult {
|
|
fn from(value: &UserCreateResult) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WhoamiResult {
|
|
pub id: String,
|
|
pub name: String,
|
|
}
|
|
|
|
impl From<&WhoamiResult> for WhoamiResult {
|
|
fn from(value: &WhoamiResult) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct Worker {
|
|
pub deleted: bool,
|
|
pub id: String,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub instance_id: Option<String>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub lastping: Option<chrono::DateTime<chrono::offset::Utc>>,
|
|
pub recycle: bool,
|
|
pub tasks: Vec<WorkerTask>,
|
|
}
|
|
|
|
impl From<&Worker> for Worker {
|
|
fn from(value: &Worker) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkerAddOutput {
|
|
pub chunks: Vec<String>,
|
|
pub path: String,
|
|
pub size: i64,
|
|
}
|
|
|
|
impl From<&WorkerAddOutput> for WorkerAddOutput {
|
|
fn from(value: &WorkerAddOutput) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkerAppendTask {
|
|
pub payload: String,
|
|
pub stream: String,
|
|
pub time: chrono::DateTime<chrono::offset::Utc>,
|
|
}
|
|
|
|
impl From<&WorkerAppendTask> for WorkerAppendTask {
|
|
fn from(value: &WorkerAppendTask) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkerBootstrap {
|
|
pub bootstrap: String,
|
|
pub token: String,
|
|
}
|
|
|
|
impl From<&WorkerBootstrap> for WorkerBootstrap {
|
|
fn from(value: &WorkerBootstrap) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkerBootstrapResult {
|
|
pub id: String,
|
|
}
|
|
|
|
impl From<&WorkerBootstrapResult> for WorkerBootstrapResult {
|
|
fn from(value: &WorkerBootstrapResult) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkerCompleteTask {
|
|
pub failed: bool,
|
|
}
|
|
|
|
impl From<&WorkerCompleteTask> for WorkerCompleteTask {
|
|
fn from(value: &WorkerCompleteTask) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkerPingResult {
|
|
pub poweroff: bool,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub task: Option<WorkerPingTask>,
|
|
}
|
|
|
|
impl From<&WorkerPingResult> for WorkerPingResult {
|
|
fn from(value: &WorkerPingResult) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkerPingTask {
|
|
pub id: String,
|
|
pub output_rules: Vec<String>,
|
|
pub script: String,
|
|
}
|
|
|
|
impl From<&WorkerPingTask> for WorkerPingTask {
|
|
fn from(value: &WorkerPingTask) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkerTask {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub owner: String,
|
|
}
|
|
|
|
impl From<&WorkerTask> for WorkerTask {
|
|
fn from(value: &WorkerTask) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct WorkersResult {
|
|
pub workers: Vec<Worker>,
|
|
}
|
|
|
|
impl From<&WorkersResult> for WorkersResult {
|
|
fn from(value: &WorkersResult) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
///Client for Buildomat
|
|
///
|
|
///Version: 1.0
|
|
pub struct Client {
|
|
pub(crate) baseurl: String,
|
|
pub(crate) client: reqwest::Client,
|
|
}
|
|
|
|
impl Client {
|
|
/// Create a new client.
|
|
///
|
|
/// `baseurl` is the base URL provided to the internal
|
|
/// `reqwest::Client`, and should include a scheme and hostname,
|
|
/// as well as port and a path stem if applicable.
|
|
pub fn new(baseurl: &str) -> Self {
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
let client = {
|
|
let dur = std::time::Duration::from_secs(15);
|
|
reqwest::ClientBuilder::new()
|
|
.connect_timeout(dur)
|
|
.timeout(dur)
|
|
};
|
|
#[cfg(target_arch = "wasm32")]
|
|
let client = reqwest::ClientBuilder::new();
|
|
Self::new_with_client(baseurl, client.build().unwrap())
|
|
}
|
|
|
|
/// Construct a new client with an existing `reqwest::Client`,
|
|
/// allowing more control over its configuration.
|
|
///
|
|
/// `baseurl` is the base URL provided to the internal
|
|
/// `reqwest::Client`, and should include a scheme and hostname,
|
|
/// as well as port and a path stem if applicable.
|
|
pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self {
|
|
Self {
|
|
baseurl: baseurl.to_string(),
|
|
client,
|
|
}
|
|
}
|
|
|
|
/// Get the base URL to which requests are made.
|
|
pub fn baseurl(&self) -> &String {
|
|
&self.baseurl
|
|
}
|
|
|
|
/// Get the internal `reqwest::Client` used to make requests.
|
|
pub fn client(&self) -> &reqwest::Client {
|
|
&self.client
|
|
}
|
|
|
|
/// Get the version of this API.
|
|
///
|
|
/// This string is pulled directly from the source OpenAPI
|
|
/// document and may be in any format the API selects.
|
|
pub fn api_version(&self) -> &'static str {
|
|
"1.0"
|
|
}
|
|
}
|
|
|
|
impl Client {
|
|
///Sends a `POST` request to `/v1/control/hold`
|
|
pub async fn control_hold<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>> {
|
|
let url = format!("{}/v1/control/hold", self.baseurl,);
|
|
let request = self
|
|
.client
|
|
.post(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/control/resume`
|
|
pub async fn control_resume<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>> {
|
|
let url = format!("{}/v1/control/resume", self.baseurl,);
|
|
let request = self.client.post(url).build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => Ok(ResponseValue::empty(response)),
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `GET` request to `/v1/task/{task}`
|
|
pub async fn task_get<'a>(
|
|
&'a self,
|
|
task: &'a str,
|
|
) -> Result<ResponseValue<types::Task>, Error<()>> {
|
|
let url = format!(
|
|
"{}/v1/task/{}",
|
|
self.baseurl,
|
|
encode_path(&task.to_string()),
|
|
);
|
|
let request = self
|
|
.client
|
|
.get(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `GET` request to `/v1/tasks`
|
|
pub async fn tasks_get<'a>(&'a self) -> Result<ResponseValue<Vec<types::Task>>, Error<()>> {
|
|
let url = format!("{}/v1/tasks", self.baseurl,);
|
|
let request = self
|
|
.client
|
|
.get(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/tasks`
|
|
pub async fn task_submit<'a>(
|
|
&'a self,
|
|
body: &'a types::TaskSubmit,
|
|
) -> Result<ResponseValue<types::TaskSubmitResult>, Error<()>> {
|
|
let url = format!("{}/v1/tasks", self.baseurl,);
|
|
let request = self
|
|
.client
|
|
.post(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.json(&body)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
201u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `GET` request to `/v1/tasks/{task}/events`
|
|
pub async fn task_events_get<'a>(
|
|
&'a self,
|
|
task: &'a str,
|
|
minseq: Option<u32>,
|
|
) -> Result<ResponseValue<Vec<types::TaskEvent>>, Error<()>> {
|
|
let url = format!(
|
|
"{}/v1/tasks/{}/events",
|
|
self.baseurl,
|
|
encode_path(&task.to_string()),
|
|
);
|
|
let mut query = Vec::with_capacity(1usize);
|
|
if let Some(v) = &minseq {
|
|
query.push(("minseq", v.to_string()));
|
|
}
|
|
|
|
let request = self
|
|
.client
|
|
.get(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.query(&query)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `GET` request to `/v1/tasks/{task}/outputs`
|
|
pub async fn task_outputs_get<'a>(
|
|
&'a self,
|
|
task: &'a str,
|
|
) -> Result<ResponseValue<Vec<types::TaskOutput>>, Error<()>> {
|
|
let url = format!(
|
|
"{}/v1/tasks/{}/outputs",
|
|
self.baseurl,
|
|
encode_path(&task.to_string()),
|
|
);
|
|
let request = self
|
|
.client
|
|
.get(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `GET` request to `/v1/tasks/{task}/outputs/{output}`
|
|
pub async fn task_output_download<'a>(
|
|
&'a self,
|
|
task: &'a str,
|
|
output: &'a str,
|
|
) -> Result<ResponseValue<ByteStream>, Error<()>> {
|
|
let url = format!(
|
|
"{}/v1/tasks/{}/outputs/{}",
|
|
self.baseurl,
|
|
encode_path(&task.to_string()),
|
|
encode_path(&output.to_string()),
|
|
);
|
|
let request = self.client.get(url).build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200..=299 => Ok(ResponseValue::stream(response)),
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/users`
|
|
pub async fn user_create<'a>(
|
|
&'a self,
|
|
body: &'a types::UserCreate,
|
|
) -> Result<ResponseValue<types::UserCreateResult>, Error<()>> {
|
|
let url = format!("{}/v1/users", self.baseurl,);
|
|
let request = self
|
|
.client
|
|
.post(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.json(&body)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
201u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `GET` request to `/v1/whoami`
|
|
pub async fn whoami<'a>(&'a self) -> Result<ResponseValue<types::WhoamiResult>, Error<()>> {
|
|
let url = format!("{}/v1/whoami", self.baseurl,);
|
|
let request = self
|
|
.client
|
|
.get(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/worker/bootstrap`
|
|
pub async fn worker_bootstrap<'a>(
|
|
&'a self,
|
|
body: &'a types::WorkerBootstrap,
|
|
) -> Result<ResponseValue<types::WorkerBootstrapResult>, Error<()>> {
|
|
let url = format!("{}/v1/worker/bootstrap", self.baseurl,);
|
|
let request = self
|
|
.client
|
|
.post(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.json(&body)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
201u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `GET` request to `/v1/worker/ping`
|
|
pub async fn worker_ping<'a>(
|
|
&'a self,
|
|
) -> Result<ResponseValue<types::WorkerPingResult>, Error<()>> {
|
|
let url = format!("{}/v1/worker/ping", self.baseurl,);
|
|
let request = self
|
|
.client
|
|
.get(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/worker/task/{task}/append`
|
|
pub async fn worker_task_append<'a>(
|
|
&'a self,
|
|
task: &'a str,
|
|
body: &'a types::WorkerAppendTask,
|
|
) -> Result<ResponseValue<()>, Error<()>> {
|
|
let url = format!(
|
|
"{}/v1/worker/task/{}/append",
|
|
self.baseurl,
|
|
encode_path(&task.to_string()),
|
|
);
|
|
let request = self.client.post(url).json(&body).build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
201u16 => Ok(ResponseValue::empty(response)),
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/worker/task/{task}/chunk`
|
|
pub async fn worker_task_upload_chunk<'a, B: Into<reqwest::Body>>(
|
|
&'a self,
|
|
task: &'a str,
|
|
body: B,
|
|
) -> Result<ResponseValue<types::UploadedChunk>, Error<()>> {
|
|
let url = format!(
|
|
"{}/v1/worker/task/{}/chunk",
|
|
self.baseurl,
|
|
encode_path(&task.to_string()),
|
|
);
|
|
let request = self
|
|
.client
|
|
.post(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.header(
|
|
reqwest::header::CONTENT_TYPE,
|
|
reqwest::header::HeaderValue::from_static("application/octet-stream"),
|
|
)
|
|
.body(body)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
201u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/worker/task/{task}/complete`
|
|
pub async fn worker_task_complete<'a>(
|
|
&'a self,
|
|
task: &'a str,
|
|
body: &'a types::WorkerCompleteTask,
|
|
) -> Result<ResponseValue<()>, Error<()>> {
|
|
let url = format!(
|
|
"{}/v1/worker/task/{}/complete",
|
|
self.baseurl,
|
|
encode_path(&task.to_string()),
|
|
);
|
|
let request = self.client.post(url).json(&body).build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => Ok(ResponseValue::empty(response)),
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/worker/task/{task}/output`
|
|
pub async fn worker_task_add_output<'a>(
|
|
&'a self,
|
|
task: &'a str,
|
|
body: &'a types::WorkerAddOutput,
|
|
) -> Result<ResponseValue<()>, Error<()>> {
|
|
let url = format!(
|
|
"{}/v1/worker/task/{}/output",
|
|
self.baseurl,
|
|
encode_path(&task.to_string()),
|
|
);
|
|
let request = self.client.post(url).json(&body).build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
201u16 => Ok(ResponseValue::empty(response)),
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `GET` request to `/v1/workers`
|
|
pub async fn workers_list<'a>(
|
|
&'a self,
|
|
) -> Result<ResponseValue<types::WorkersResult>, Error<()>> {
|
|
let url = format!("{}/v1/workers", self.baseurl,);
|
|
let request = self
|
|
.client
|
|
.get(url)
|
|
.header(
|
|
reqwest::header::ACCEPT,
|
|
reqwest::header::HeaderValue::from_static("application/json"),
|
|
)
|
|
.build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => ResponseValue::from_response(response).await,
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
|
|
///Sends a `POST` request to `/v1/workers/recycle`
|
|
pub async fn workers_recycle<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>> {
|
|
let url = format!("{}/v1/workers/recycle", self.baseurl,);
|
|
let request = self.client.post(url).build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => Ok(ResponseValue::empty(response)),
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub mod prelude {
|
|
pub use super::Client;
|
|
}
|