progenitor/progenitor-impl/tests/output/buildomat-builder.out

1158 lines
37 KiB
Plaintext

#[allow(unused_imports)]
use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types {
use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct Task {
pub id: String,
pub name: String,
pub output_rules: Vec<String>,
pub script: String,
pub state: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct TaskEvent {
pub payload: String,
pub seq: u32,
pub stream: String,
pub time: chrono::DateTime<chrono::offset::Utc>,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct TaskOutput {
pub id: String,
pub path: String,
pub size: u64,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct TaskSubmit {
pub name: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub output_rules: Vec<String>,
pub script: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct TaskSubmitResult {
pub id: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct UploadedChunk {
pub id: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct UserCreate {
pub name: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct UserCreateResult {
pub id: String,
pub name: String,
pub token: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WhoamiResult {
pub id: String,
pub name: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
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>,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkerAddOutput {
pub chunks: Vec<String>,
pub path: String,
pub size: i64,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkerAppendTask {
pub payload: String,
pub stream: String,
pub time: chrono::DateTime<chrono::offset::Utc>,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkerBootstrap {
pub bootstrap: String,
pub token: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkerBootstrapResult {
pub id: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkerCompleteTask {
pub failed: bool,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkerPingResult {
pub poweroff: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub task: Option<WorkerPingTask>,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkerPingTask {
pub id: String,
pub output_rules: Vec<String>,
pub script: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkerTask {
pub id: String,
pub name: String,
pub owner: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct WorkersResult {
pub workers: Vec<Worker>,
}
}
#[derive(Clone, Debug)]
pub struct Client {
pub(crate) baseurl: String,
pub(crate) client: reqwest::Client,
}
impl Client {
pub fn new(baseurl: &str) -> Self {
let dur = std::time::Duration::from_secs(15);
let client = reqwest::ClientBuilder::new()
.connect_timeout(dur)
.timeout(dur)
.build()
.unwrap();
Self::new_with_client(baseurl, client)
}
pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self {
Self {
baseurl: baseurl.to_string(),
client,
}
}
pub fn baseurl(&self) -> &String {
&self.baseurl
}
pub fn client(&self) -> &reqwest::Client {
&self.client
}
}
impl Client {
///Sends a `POST` request to `/v1/control/hold`
///```ignore
/// let response = client.control_hold()
/// .send()
/// .await;
/// ```
pub fn control_hold(&self) -> builder::ControlHold {
builder::ControlHold::new(self)
}
///Sends a `POST` request to `/v1/control/resume`
///```ignore
/// let response = client.control_resume()
/// .send()
/// .await;
/// ```
pub fn control_resume(&self) -> builder::ControlResume {
builder::ControlResume::new(self)
}
///Sends a `GET` request to `/v1/task/{task}`
///```ignore
/// let response = client.task_get()
/// .task(task)
/// .send()
/// .await;
/// ```
pub fn task_get(&self) -> builder::TaskGet {
builder::TaskGet::new(self)
}
///Sends a `GET` request to `/v1/tasks`
///```ignore
/// let response = client.tasks_get()
/// .send()
/// .await;
/// ```
pub fn tasks_get(&self) -> builder::TasksGet {
builder::TasksGet::new(self)
}
///Sends a `POST` request to `/v1/tasks`
///```ignore
/// let response = client.task_submit()
/// .body(body)
/// .send()
/// .await;
/// ```
pub fn task_submit(&self) -> builder::TaskSubmit {
builder::TaskSubmit::new(self)
}
///Sends a `GET` request to `/v1/tasks/{task}/events`
///```ignore
/// let response = client.task_events_get()
/// .task(task)
/// .minseq(minseq)
/// .send()
/// .await;
/// ```
pub fn task_events_get(&self) -> builder::TaskEventsGet {
builder::TaskEventsGet::new(self)
}
///Sends a `GET` request to `/v1/tasks/{task}/outputs`
///```ignore
/// let response = client.task_outputs_get()
/// .task(task)
/// .send()
/// .await;
/// ```
pub fn task_outputs_get(&self) -> builder::TaskOutputsGet {
builder::TaskOutputsGet::new(self)
}
///Sends a `GET` request to `/v1/tasks/{task}/outputs/{output}`
///```ignore
/// let response = client.task_output_download()
/// .task(task)
/// .output(output)
/// .send()
/// .await;
/// ```
pub fn task_output_download(&self) -> builder::TaskOutputDownload {
builder::TaskOutputDownload::new(self)
}
///Sends a `POST` request to `/v1/users`
///```ignore
/// let response = client.user_create()
/// .body(body)
/// .send()
/// .await;
/// ```
pub fn user_create(&self) -> builder::UserCreate {
builder::UserCreate::new(self)
}
///Sends a `GET` request to `/v1/whoami`
///```ignore
/// let response = client.whoami()
/// .send()
/// .await;
/// ```
pub fn whoami(&self) -> builder::Whoami {
builder::Whoami::new(self)
}
///Sends a `POST` request to `/v1/worker/bootstrap`
///```ignore
/// let response = client.worker_bootstrap()
/// .body(body)
/// .send()
/// .await;
/// ```
pub fn worker_bootstrap(&self) -> builder::WorkerBootstrap {
builder::WorkerBootstrap::new(self)
}
///Sends a `GET` request to `/v1/worker/ping`
///```ignore
/// let response = client.worker_ping()
/// .send()
/// .await;
/// ```
pub fn worker_ping(&self) -> builder::WorkerPing {
builder::WorkerPing::new(self)
}
///Sends a `POST` request to `/v1/worker/task/{task}/append`
///```ignore
/// let response = client.worker_task_append()
/// .task(task)
/// .body(body)
/// .send()
/// .await;
/// ```
pub fn worker_task_append(&self) -> builder::WorkerTaskAppend {
builder::WorkerTaskAppend::new(self)
}
///Sends a `POST` request to `/v1/worker/task/{task}/chunk`
///```ignore
/// let response = client.worker_task_upload_chunk()
/// .task(task)
/// .body(body)
/// .send()
/// .await;
/// ```
pub fn worker_task_upload_chunk(&self) -> builder::WorkerTaskUploadChunk {
builder::WorkerTaskUploadChunk::new(self)
}
///Sends a `POST` request to `/v1/worker/task/{task}/complete`
///```ignore
/// let response = client.worker_task_complete()
/// .task(task)
/// .body(body)
/// .send()
/// .await;
/// ```
pub fn worker_task_complete(&self) -> builder::WorkerTaskComplete {
builder::WorkerTaskComplete::new(self)
}
///Sends a `POST` request to `/v1/worker/task/{task}/output`
///```ignore
/// let response = client.worker_task_add_output()
/// .task(task)
/// .body(body)
/// .send()
/// .await;
/// ```
pub fn worker_task_add_output(&self) -> builder::WorkerTaskAddOutput {
builder::WorkerTaskAddOutput::new(self)
}
///Sends a `GET` request to `/v1/workers`
///```ignore
/// let response = client.workers_list()
/// .send()
/// .await;
/// ```
pub fn workers_list(&self) -> builder::WorkersList {
builder::WorkersList::new(self)
}
///Sends a `POST` request to `/v1/workers/recycle`
///```ignore
/// let response = client.workers_recycle()
/// .send()
/// .await;
/// ```
pub fn workers_recycle(&self) -> builder::WorkersRecycle {
builder::WorkersRecycle::new(self)
}
}
pub mod builder {
use super::types;
#[allow(unused_imports)]
use super::{encode_path, ByteStream, Error, RequestBuilderExt, ResponseValue};
#[allow(unused_imports)]
use std::convert::TryInto;
///Builder for [`Client::control_hold`]
///
///[`Client::control_hold`]: super::Client::control_hold
#[derive(Debug, Clone)]
pub struct ControlHold<'a> {
client: &'a super::Client,
}
impl<'a> ControlHold<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self { client }
}
///Sends a `POST` request to `/v1/control/hold`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/control/hold", client.baseurl,);
let request = client.client.post(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::control_resume`]
///
///[`Client::control_resume`]: super::Client::control_resume
#[derive(Debug, Clone)]
pub struct ControlResume<'a> {
client: &'a super::Client,
}
impl<'a> ControlResume<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self { client }
}
///Sends a `POST` request to `/v1/control/resume`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/control/resume", client.baseurl,);
let request = client.client.post(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::task_get`]
///
///[`Client::task_get`]: super::Client::task_get
#[derive(Debug, Clone)]
pub struct TaskGet<'a> {
client: &'a super::Client,
task: Result<String, String>,
}
impl<'a> TaskGet<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
task: Err("task was not initialized".to_string()),
}
}
pub fn task<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self
}
///Sends a `GET` request to `/v1/task/{task}`
pub async fn send(self) -> Result<ResponseValue<types::Task>, Error<()>> {
let Self { client, task } = self;
let task = task.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/task/{}",
client.baseurl,
encode_path(&task.to_string()),
);
let request = client.client.get(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::tasks_get`]
///
///[`Client::tasks_get`]: super::Client::tasks_get
#[derive(Debug, Clone)]
pub struct TasksGet<'a> {
client: &'a super::Client,
}
impl<'a> TasksGet<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self { client }
}
///Sends a `GET` request to `/v1/tasks`
pub async fn send(self) -> Result<ResponseValue<Vec<types::Task>>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/tasks", client.baseurl,);
let request = client.client.get(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::task_submit`]
///
///[`Client::task_submit`]: super::Client::task_submit
#[derive(Debug, Clone)]
pub struct TaskSubmit<'a> {
client: &'a super::Client,
body: Result<types::TaskSubmit, String>,
}
impl<'a> TaskSubmit<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
body: Err("body was not initialized".to_string()),
}
}
pub fn body<V>(mut self, value: V) -> Self
where
V: TryInto<types::TaskSubmit>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `TaskSubmit` for body failed".to_string());
self
}
///Sends a `POST` request to `/v1/tasks`
pub async fn send(self) -> Result<ResponseValue<types::TaskSubmitResult>, Error<()>> {
let Self { client, body } = self;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!("{}/v1/tasks", client.baseurl,);
let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
201u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::task_events_get`]
///
///[`Client::task_events_get`]: super::Client::task_events_get
#[derive(Debug, Clone)]
pub struct TaskEventsGet<'a> {
client: &'a super::Client,
task: Result<String, String>,
minseq: Result<Option<u32>, String>,
}
impl<'a> TaskEventsGet<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
task: Err("task was not initialized".to_string()),
minseq: Ok(None),
}
}
pub fn task<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self
}
pub fn minseq<V>(mut self, value: V) -> Self
where
V: TryInto<u32>,
{
self.minseq = value
.try_into()
.map(Some)
.map_err(|_| "conversion to `Option < u32 >` for minseq failed".to_string());
self
}
///Sends a `GET` request to `/v1/tasks/{task}/events`
pub async fn send(self) -> Result<ResponseValue<Vec<types::TaskEvent>>, Error<()>> {
let Self {
client,
task,
minseq,
} = self;
let task = task.map_err(Error::InvalidRequest)?;
let minseq = minseq.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/tasks/{}/events",
client.baseurl,
encode_path(&task.to_string()),
);
let mut query = Vec::new();
if let Some(v) = &minseq {
query.push(("minseq", v.to_string()));
}
let request = client.client.get(url).query(&query).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::task_outputs_get`]
///
///[`Client::task_outputs_get`]: super::Client::task_outputs_get
#[derive(Debug, Clone)]
pub struct TaskOutputsGet<'a> {
client: &'a super::Client,
task: Result<String, String>,
}
impl<'a> TaskOutputsGet<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
task: Err("task was not initialized".to_string()),
}
}
pub fn task<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self
}
///Sends a `GET` request to `/v1/tasks/{task}/outputs`
pub async fn send(self) -> Result<ResponseValue<Vec<types::TaskOutput>>, Error<()>> {
let Self { client, task } = self;
let task = task.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/tasks/{}/outputs",
client.baseurl,
encode_path(&task.to_string()),
);
let request = client.client.get(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::task_output_download`]
///
///[`Client::task_output_download`]: super::Client::task_output_download
#[derive(Debug, Clone)]
pub struct TaskOutputDownload<'a> {
client: &'a super::Client,
task: Result<String, String>,
output: Result<String, String>,
}
impl<'a> TaskOutputDownload<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
task: Err("task was not initialized".to_string()),
output: Err("output was not initialized".to_string()),
}
}
pub fn task<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self
}
pub fn output<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.output = value
.try_into()
.map_err(|_| "conversion to `String` for output failed".to_string());
self
}
///Sends a `GET` request to `/v1/tasks/{task}/outputs/{output}`
pub async fn send(self) -> Result<ResponseValue<ByteStream>, Error<()>> {
let Self {
client,
task,
output,
} = self;
let task = task.map_err(Error::InvalidRequest)?;
let output = output.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/tasks/{}/outputs/{}",
client.baseurl,
encode_path(&task.to_string()),
encode_path(&output.to_string()),
);
let request = client.client.get(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200..=299 => Ok(ResponseValue::stream(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::user_create`]
///
///[`Client::user_create`]: super::Client::user_create
#[derive(Debug, Clone)]
pub struct UserCreate<'a> {
client: &'a super::Client,
body: Result<types::UserCreate, String>,
}
impl<'a> UserCreate<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
body: Err("body was not initialized".to_string()),
}
}
pub fn body<V>(mut self, value: V) -> Self
where
V: TryInto<types::UserCreate>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `UserCreate` for body failed".to_string());
self
}
///Sends a `POST` request to `/v1/users`
pub async fn send(self) -> Result<ResponseValue<types::UserCreateResult>, Error<()>> {
let Self { client, body } = self;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!("{}/v1/users", client.baseurl,);
let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
201u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::whoami`]
///
///[`Client::whoami`]: super::Client::whoami
#[derive(Debug, Clone)]
pub struct Whoami<'a> {
client: &'a super::Client,
}
impl<'a> Whoami<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self { client }
}
///Sends a `GET` request to `/v1/whoami`
pub async fn send(self) -> Result<ResponseValue<types::WhoamiResult>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/whoami", client.baseurl,);
let request = client.client.get(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::worker_bootstrap`]
///
///[`Client::worker_bootstrap`]: super::Client::worker_bootstrap
#[derive(Debug, Clone)]
pub struct WorkerBootstrap<'a> {
client: &'a super::Client,
body: Result<types::WorkerBootstrap, String>,
}
impl<'a> WorkerBootstrap<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
body: Err("body was not initialized".to_string()),
}
}
pub fn body<V>(mut self, value: V) -> Self
where
V: TryInto<types::WorkerBootstrap>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerBootstrap` for body failed".to_string());
self
}
///Sends a `POST` request to `/v1/worker/bootstrap`
pub async fn send(self) -> Result<ResponseValue<types::WorkerBootstrapResult>, Error<()>> {
let Self { client, body } = self;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!("{}/v1/worker/bootstrap", client.baseurl,);
let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
201u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::worker_ping`]
///
///[`Client::worker_ping`]: super::Client::worker_ping
#[derive(Debug, Clone)]
pub struct WorkerPing<'a> {
client: &'a super::Client,
}
impl<'a> WorkerPing<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self { client }
}
///Sends a `GET` request to `/v1/worker/ping`
pub async fn send(self) -> Result<ResponseValue<types::WorkerPingResult>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/worker/ping", client.baseurl,);
let request = client.client.get(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::worker_task_append`]
///
///[`Client::worker_task_append`]: super::Client::worker_task_append
#[derive(Debug, Clone)]
pub struct WorkerTaskAppend<'a> {
client: &'a super::Client,
task: Result<String, String>,
body: Result<types::WorkerAppendTask, String>,
}
impl<'a> WorkerTaskAppend<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
task: Err("task was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn task<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: TryInto<types::WorkerAppendTask>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerAppendTask` for body failed".to_string());
self
}
///Sends a `POST` request to `/v1/worker/task/{task}/append`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self;
let task = task.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/worker/task/{}/append",
client.baseurl,
encode_path(&task.to_string()),
);
let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
201u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::worker_task_upload_chunk`]
///
///[`Client::worker_task_upload_chunk`]: super::Client::worker_task_upload_chunk
#[derive(Debug)]
pub struct WorkerTaskUploadChunk<'a> {
client: &'a super::Client,
task: Result<String, String>,
body: Result<reqwest::Body, String>,
}
impl<'a> WorkerTaskUploadChunk<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
task: Err("task was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn task<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self
}
pub fn body<B>(mut self, value: B) -> Self
where
B: TryInto<reqwest::Body>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `reqwest::Body` for body failed".to_string());
self
}
///Sends a `POST` request to `/v1/worker/task/{task}/chunk`
pub async fn send(self) -> Result<ResponseValue<types::UploadedChunk>, Error<()>> {
let Self { client, task, body } = self;
let task = task.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/worker/task/{}/chunk",
client.baseurl,
encode_path(&task.to_string()),
);
let request = client
.client
.post(url)
.header(
reqwest::header::CONTENT_TYPE,
reqwest::header::HeaderValue::from_static("application/octet-stream"),
)
.body(body)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
201u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::worker_task_complete`]
///
///[`Client::worker_task_complete`]: super::Client::worker_task_complete
#[derive(Debug, Clone)]
pub struct WorkerTaskComplete<'a> {
client: &'a super::Client,
task: Result<String, String>,
body: Result<types::WorkerCompleteTask, String>,
}
impl<'a> WorkerTaskComplete<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
task: Err("task was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn task<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: TryInto<types::WorkerCompleteTask>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerCompleteTask` for body failed".to_string());
self
}
///Sends a `POST` request to `/v1/worker/task/{task}/complete`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self;
let task = task.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/worker/task/{}/complete",
client.baseurl,
encode_path(&task.to_string()),
);
let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::worker_task_add_output`]
///
///[`Client::worker_task_add_output`]: super::Client::worker_task_add_output
#[derive(Debug, Clone)]
pub struct WorkerTaskAddOutput<'a> {
client: &'a super::Client,
task: Result<String, String>,
body: Result<types::WorkerAddOutput, String>,
}
impl<'a> WorkerTaskAddOutput<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
task: Err("task was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn task<V>(mut self, value: V) -> Self
where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: TryInto<types::WorkerAddOutput>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerAddOutput` for body failed".to_string());
self
}
///Sends a `POST` request to `/v1/worker/task/{task}/output`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self;
let task = task.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/worker/task/{}/output",
client.baseurl,
encode_path(&task.to_string()),
);
let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
201u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::workers_list`]
///
///[`Client::workers_list`]: super::Client::workers_list
#[derive(Debug, Clone)]
pub struct WorkersList<'a> {
client: &'a super::Client,
}
impl<'a> WorkersList<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self { client }
}
///Sends a `GET` request to `/v1/workers`
pub async fn send(self) -> Result<ResponseValue<types::WorkersResult>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/workers", client.baseurl,);
let request = client.client.get(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::workers_recycle`]
///
///[`Client::workers_recycle`]: super::Client::workers_recycle
#[derive(Debug, Clone)]
pub struct WorkersRecycle<'a> {
client: &'a super::Client,
}
impl<'a> WorkersRecycle<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self { client }
}
///Sends a `POST` request to `/v1/workers/recycle`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/workers/recycle", client.baseurl,);
let request = client.client.post(url).build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
}