2291 lines
74 KiB
Plaintext
2291 lines
74 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,
|
|
}
|
|
|
|
impl Task {
|
|
pub fn builder() -> builder::Task {
|
|
builder::Task::default()
|
|
}
|
|
}
|
|
|
|
#[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>,
|
|
}
|
|
|
|
impl TaskEvent {
|
|
pub fn builder() -> builder::TaskEvent {
|
|
builder::TaskEvent::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct TaskOutput {
|
|
pub id: String,
|
|
pub path: String,
|
|
pub size: u64,
|
|
}
|
|
|
|
impl TaskOutput {
|
|
pub fn builder() -> builder::TaskOutput {
|
|
builder::TaskOutput::default()
|
|
}
|
|
}
|
|
|
|
#[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,
|
|
}
|
|
|
|
impl TaskSubmit {
|
|
pub fn builder() -> builder::TaskSubmit {
|
|
builder::TaskSubmit::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct TaskSubmitResult {
|
|
pub id: String,
|
|
}
|
|
|
|
impl TaskSubmitResult {
|
|
pub fn builder() -> builder::TaskSubmitResult {
|
|
builder::TaskSubmitResult::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct UploadedChunk {
|
|
pub id: String,
|
|
}
|
|
|
|
impl UploadedChunk {
|
|
pub fn builder() -> builder::UploadedChunk {
|
|
builder::UploadedChunk::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct UserCreate {
|
|
pub name: String,
|
|
}
|
|
|
|
impl UserCreate {
|
|
pub fn builder() -> builder::UserCreate {
|
|
builder::UserCreate::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct UserCreateResult {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub token: String,
|
|
}
|
|
|
|
impl UserCreateResult {
|
|
pub fn builder() -> builder::UserCreateResult {
|
|
builder::UserCreateResult::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WhoamiResult {
|
|
pub id: String,
|
|
pub name: String,
|
|
}
|
|
|
|
impl WhoamiResult {
|
|
pub fn builder() -> builder::WhoamiResult {
|
|
builder::WhoamiResult::default()
|
|
}
|
|
}
|
|
|
|
#[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>,
|
|
}
|
|
|
|
impl Worker {
|
|
pub fn builder() -> builder::Worker {
|
|
builder::Worker::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkerAddOutput {
|
|
pub chunks: Vec<String>,
|
|
pub path: String,
|
|
pub size: i64,
|
|
}
|
|
|
|
impl WorkerAddOutput {
|
|
pub fn builder() -> builder::WorkerAddOutput {
|
|
builder::WorkerAddOutput::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkerAppendTask {
|
|
pub payload: String,
|
|
pub stream: String,
|
|
pub time: chrono::DateTime<chrono::offset::Utc>,
|
|
}
|
|
|
|
impl WorkerAppendTask {
|
|
pub fn builder() -> builder::WorkerAppendTask {
|
|
builder::WorkerAppendTask::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkerBootstrap {
|
|
pub bootstrap: String,
|
|
pub token: String,
|
|
}
|
|
|
|
impl WorkerBootstrap {
|
|
pub fn builder() -> builder::WorkerBootstrap {
|
|
builder::WorkerBootstrap::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkerBootstrapResult {
|
|
pub id: String,
|
|
}
|
|
|
|
impl WorkerBootstrapResult {
|
|
pub fn builder() -> builder::WorkerBootstrapResult {
|
|
builder::WorkerBootstrapResult::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkerCompleteTask {
|
|
pub failed: bool,
|
|
}
|
|
|
|
impl WorkerCompleteTask {
|
|
pub fn builder() -> builder::WorkerCompleteTask {
|
|
builder::WorkerCompleteTask::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkerPingResult {
|
|
pub poweroff: bool,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub task: Option<WorkerPingTask>,
|
|
}
|
|
|
|
impl WorkerPingResult {
|
|
pub fn builder() -> builder::WorkerPingResult {
|
|
builder::WorkerPingResult::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkerPingTask {
|
|
pub id: String,
|
|
pub output_rules: Vec<String>,
|
|
pub script: String,
|
|
}
|
|
|
|
impl WorkerPingTask {
|
|
pub fn builder() -> builder::WorkerPingTask {
|
|
builder::WorkerPingTask::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkerTask {
|
|
pub id: String,
|
|
pub name: String,
|
|
pub owner: String,
|
|
}
|
|
|
|
impl WorkerTask {
|
|
pub fn builder() -> builder::WorkerTask {
|
|
builder::WorkerTask::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub struct WorkersResult {
|
|
pub workers: Vec<Worker>,
|
|
}
|
|
|
|
impl WorkersResult {
|
|
pub fn builder() -> builder::WorkersResult {
|
|
builder::WorkersResult::default()
|
|
}
|
|
}
|
|
|
|
mod builder {
|
|
pub struct Task {
|
|
id: Result<String, String>,
|
|
name: Result<String, String>,
|
|
output_rules: Result<Vec<String>, String>,
|
|
script: Result<String, String>,
|
|
state: Result<String, String>,
|
|
}
|
|
|
|
impl Default for Task {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
name: Err("no value supplied for name".to_string()),
|
|
output_rules: Err("no value supplied for output_rules".to_string()),
|
|
script: Err("no value supplied for script".to_string()),
|
|
state: Err("no value supplied for state".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Task {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
pub fn name<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.name = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for name: {}", e));
|
|
self
|
|
}
|
|
pub fn output_rules<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Vec<String>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.output_rules = value.try_into().map_err(|e| {
|
|
format!("error converting supplied value for output_rules: {}", e)
|
|
});
|
|
self
|
|
}
|
|
pub fn script<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.script = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for script: {}", e));
|
|
self
|
|
}
|
|
pub fn state<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.state = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for state: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<Task> for super::Task {
|
|
type Error = String;
|
|
fn try_from(value: Task) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
id: value.id?,
|
|
name: value.name?,
|
|
output_rules: value.output_rules?,
|
|
script: value.script?,
|
|
state: value.state?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct TaskEvent {
|
|
payload: Result<String, String>,
|
|
seq: Result<u32, String>,
|
|
stream: Result<String, String>,
|
|
time: Result<chrono::DateTime<chrono::offset::Utc>, String>,
|
|
}
|
|
|
|
impl Default for TaskEvent {
|
|
fn default() -> Self {
|
|
Self {
|
|
payload: Err("no value supplied for payload".to_string()),
|
|
seq: Err("no value supplied for seq".to_string()),
|
|
stream: Err("no value supplied for stream".to_string()),
|
|
time: Err("no value supplied for time".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TaskEvent {
|
|
pub fn payload<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.payload = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for payload: {}", e));
|
|
self
|
|
}
|
|
pub fn seq<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<u32>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.seq = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for seq: {}", e));
|
|
self
|
|
}
|
|
pub fn stream<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.stream = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for stream: {}", e));
|
|
self
|
|
}
|
|
pub fn time<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.time = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for time: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<TaskEvent> for super::TaskEvent {
|
|
type Error = String;
|
|
fn try_from(value: TaskEvent) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
payload: value.payload?,
|
|
seq: value.seq?,
|
|
stream: value.stream?,
|
|
time: value.time?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct TaskOutput {
|
|
id: Result<String, String>,
|
|
path: Result<String, String>,
|
|
size: Result<u64, String>,
|
|
}
|
|
|
|
impl Default for TaskOutput {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
path: Err("no value supplied for path".to_string()),
|
|
size: Err("no value supplied for size".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TaskOutput {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
pub fn path<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.path = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for path: {}", e));
|
|
self
|
|
}
|
|
pub fn size<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<u64>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.size = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for size: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<TaskOutput> for super::TaskOutput {
|
|
type Error = String;
|
|
fn try_from(value: TaskOutput) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
id: value.id?,
|
|
path: value.path?,
|
|
size: value.size?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct TaskSubmit {
|
|
name: Result<String, String>,
|
|
output_rules: Result<Vec<String>, String>,
|
|
script: Result<String, String>,
|
|
}
|
|
|
|
impl Default for TaskSubmit {
|
|
fn default() -> Self {
|
|
Self {
|
|
name: Err("no value supplied for name".to_string()),
|
|
output_rules: Ok(Default::default()),
|
|
script: Err("no value supplied for script".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TaskSubmit {
|
|
pub fn name<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.name = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for name: {}", e));
|
|
self
|
|
}
|
|
pub fn output_rules<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Vec<String>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.output_rules = value.try_into().map_err(|e| {
|
|
format!("error converting supplied value for output_rules: {}", e)
|
|
});
|
|
self
|
|
}
|
|
pub fn script<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.script = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for script: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<TaskSubmit> for super::TaskSubmit {
|
|
type Error = String;
|
|
fn try_from(value: TaskSubmit) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
name: value.name?,
|
|
output_rules: value.output_rules?,
|
|
script: value.script?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct TaskSubmitResult {
|
|
id: Result<String, String>,
|
|
}
|
|
|
|
impl Default for TaskSubmitResult {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TaskSubmitResult {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<TaskSubmitResult> for super::TaskSubmitResult {
|
|
type Error = String;
|
|
fn try_from(value: TaskSubmitResult) -> Result<Self, Self::Error> {
|
|
Ok(Self { id: value.id? })
|
|
}
|
|
}
|
|
|
|
pub struct UploadedChunk {
|
|
id: Result<String, String>,
|
|
}
|
|
|
|
impl Default for UploadedChunk {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl UploadedChunk {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<UploadedChunk> for super::UploadedChunk {
|
|
type Error = String;
|
|
fn try_from(value: UploadedChunk) -> Result<Self, Self::Error> {
|
|
Ok(Self { id: value.id? })
|
|
}
|
|
}
|
|
|
|
pub struct UserCreate {
|
|
name: Result<String, String>,
|
|
}
|
|
|
|
impl Default for UserCreate {
|
|
fn default() -> Self {
|
|
Self {
|
|
name: Err("no value supplied for name".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl UserCreate {
|
|
pub fn name<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.name = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for name: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<UserCreate> for super::UserCreate {
|
|
type Error = String;
|
|
fn try_from(value: UserCreate) -> Result<Self, Self::Error> {
|
|
Ok(Self { name: value.name? })
|
|
}
|
|
}
|
|
|
|
pub struct UserCreateResult {
|
|
id: Result<String, String>,
|
|
name: Result<String, String>,
|
|
token: Result<String, String>,
|
|
}
|
|
|
|
impl Default for UserCreateResult {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
name: Err("no value supplied for name".to_string()),
|
|
token: Err("no value supplied for token".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl UserCreateResult {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
pub fn name<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.name = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for name: {}", e));
|
|
self
|
|
}
|
|
pub fn token<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.token = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for token: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<UserCreateResult> for super::UserCreateResult {
|
|
type Error = String;
|
|
fn try_from(value: UserCreateResult) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
id: value.id?,
|
|
name: value.name?,
|
|
token: value.token?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WhoamiResult {
|
|
id: Result<String, String>,
|
|
name: Result<String, String>,
|
|
}
|
|
|
|
impl Default for WhoamiResult {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
name: Err("no value supplied for name".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WhoamiResult {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
pub fn name<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.name = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for name: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WhoamiResult> for super::WhoamiResult {
|
|
type Error = String;
|
|
fn try_from(value: WhoamiResult) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
id: value.id?,
|
|
name: value.name?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct Worker {
|
|
deleted: Result<bool, String>,
|
|
id: Result<String, String>,
|
|
instance_id: Result<Option<String>, String>,
|
|
lastping: Result<Option<chrono::DateTime<chrono::offset::Utc>>, String>,
|
|
recycle: Result<bool, String>,
|
|
tasks: Result<Vec<super::WorkerTask>, String>,
|
|
}
|
|
|
|
impl Default for Worker {
|
|
fn default() -> Self {
|
|
Self {
|
|
deleted: Err("no value supplied for deleted".to_string()),
|
|
id: Err("no value supplied for id".to_string()),
|
|
instance_id: Ok(Default::default()),
|
|
lastping: Ok(Default::default()),
|
|
recycle: Err("no value supplied for recycle".to_string()),
|
|
tasks: Err("no value supplied for tasks".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Worker {
|
|
pub fn deleted<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<bool>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.deleted = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for deleted: {}", e));
|
|
self
|
|
}
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
pub fn instance_id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Option<String>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.instance_id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for instance_id: {}", e));
|
|
self
|
|
}
|
|
pub fn lastping<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Option<chrono::DateTime<chrono::offset::Utc>>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.lastping = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for lastping: {}", e));
|
|
self
|
|
}
|
|
pub fn recycle<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<bool>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.recycle = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for recycle: {}", e));
|
|
self
|
|
}
|
|
pub fn tasks<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Vec<super::WorkerTask>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.tasks = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for tasks: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<Worker> for super::Worker {
|
|
type Error = String;
|
|
fn try_from(value: Worker) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
deleted: value.deleted?,
|
|
id: value.id?,
|
|
instance_id: value.instance_id?,
|
|
lastping: value.lastping?,
|
|
recycle: value.recycle?,
|
|
tasks: value.tasks?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WorkerAddOutput {
|
|
chunks: Result<Vec<String>, String>,
|
|
path: Result<String, String>,
|
|
size: Result<i64, String>,
|
|
}
|
|
|
|
impl Default for WorkerAddOutput {
|
|
fn default() -> Self {
|
|
Self {
|
|
chunks: Err("no value supplied for chunks".to_string()),
|
|
path: Err("no value supplied for path".to_string()),
|
|
size: Err("no value supplied for size".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkerAddOutput {
|
|
pub fn chunks<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Vec<String>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.chunks = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for chunks: {}", e));
|
|
self
|
|
}
|
|
pub fn path<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.path = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for path: {}", e));
|
|
self
|
|
}
|
|
pub fn size<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<i64>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.size = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for size: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkerAddOutput> for super::WorkerAddOutput {
|
|
type Error = String;
|
|
fn try_from(value: WorkerAddOutput) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
chunks: value.chunks?,
|
|
path: value.path?,
|
|
size: value.size?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WorkerAppendTask {
|
|
payload: Result<String, String>,
|
|
stream: Result<String, String>,
|
|
time: Result<chrono::DateTime<chrono::offset::Utc>, String>,
|
|
}
|
|
|
|
impl Default for WorkerAppendTask {
|
|
fn default() -> Self {
|
|
Self {
|
|
payload: Err("no value supplied for payload".to_string()),
|
|
stream: Err("no value supplied for stream".to_string()),
|
|
time: Err("no value supplied for time".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkerAppendTask {
|
|
pub fn payload<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.payload = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for payload: {}", e));
|
|
self
|
|
}
|
|
pub fn stream<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.stream = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for stream: {}", e));
|
|
self
|
|
}
|
|
pub fn time<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.time = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for time: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkerAppendTask> for super::WorkerAppendTask {
|
|
type Error = String;
|
|
fn try_from(value: WorkerAppendTask) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
payload: value.payload?,
|
|
stream: value.stream?,
|
|
time: value.time?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WorkerBootstrap {
|
|
bootstrap: Result<String, String>,
|
|
token: Result<String, String>,
|
|
}
|
|
|
|
impl Default for WorkerBootstrap {
|
|
fn default() -> Self {
|
|
Self {
|
|
bootstrap: Err("no value supplied for bootstrap".to_string()),
|
|
token: Err("no value supplied for token".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkerBootstrap {
|
|
pub fn bootstrap<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.bootstrap = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for bootstrap: {}", e));
|
|
self
|
|
}
|
|
pub fn token<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.token = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for token: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkerBootstrap> for super::WorkerBootstrap {
|
|
type Error = String;
|
|
fn try_from(value: WorkerBootstrap) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
bootstrap: value.bootstrap?,
|
|
token: value.token?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WorkerBootstrapResult {
|
|
id: Result<String, String>,
|
|
}
|
|
|
|
impl Default for WorkerBootstrapResult {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkerBootstrapResult {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkerBootstrapResult> for super::WorkerBootstrapResult {
|
|
type Error = String;
|
|
fn try_from(value: WorkerBootstrapResult) -> Result<Self, Self::Error> {
|
|
Ok(Self { id: value.id? })
|
|
}
|
|
}
|
|
|
|
pub struct WorkerCompleteTask {
|
|
failed: Result<bool, String>,
|
|
}
|
|
|
|
impl Default for WorkerCompleteTask {
|
|
fn default() -> Self {
|
|
Self {
|
|
failed: Err("no value supplied for failed".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkerCompleteTask {
|
|
pub fn failed<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<bool>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.failed = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for failed: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkerCompleteTask> for super::WorkerCompleteTask {
|
|
type Error = String;
|
|
fn try_from(value: WorkerCompleteTask) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
failed: value.failed?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WorkerPingResult {
|
|
poweroff: Result<bool, String>,
|
|
task: Result<Option<super::WorkerPingTask>, String>,
|
|
}
|
|
|
|
impl Default for WorkerPingResult {
|
|
fn default() -> Self {
|
|
Self {
|
|
poweroff: Err("no value supplied for poweroff".to_string()),
|
|
task: Ok(Default::default()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkerPingResult {
|
|
pub fn poweroff<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<bool>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.poweroff = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for poweroff: {}", e));
|
|
self
|
|
}
|
|
pub fn task<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Option<super::WorkerPingTask>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.task = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for task: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkerPingResult> for super::WorkerPingResult {
|
|
type Error = String;
|
|
fn try_from(value: WorkerPingResult) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
poweroff: value.poweroff?,
|
|
task: value.task?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WorkerPingTask {
|
|
id: Result<String, String>,
|
|
output_rules: Result<Vec<String>, String>,
|
|
script: Result<String, String>,
|
|
}
|
|
|
|
impl Default for WorkerPingTask {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
output_rules: Err("no value supplied for output_rules".to_string()),
|
|
script: Err("no value supplied for script".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkerPingTask {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
pub fn output_rules<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Vec<String>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.output_rules = value.try_into().map_err(|e| {
|
|
format!("error converting supplied value for output_rules: {}", e)
|
|
});
|
|
self
|
|
}
|
|
pub fn script<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.script = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for script: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkerPingTask> for super::WorkerPingTask {
|
|
type Error = String;
|
|
fn try_from(value: WorkerPingTask) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
id: value.id?,
|
|
output_rules: value.output_rules?,
|
|
script: value.script?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WorkerTask {
|
|
id: Result<String, String>,
|
|
name: Result<String, String>,
|
|
owner: Result<String, String>,
|
|
}
|
|
|
|
impl Default for WorkerTask {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: Err("no value supplied for id".to_string()),
|
|
name: Err("no value supplied for name".to_string()),
|
|
owner: Err("no value supplied for owner".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkerTask {
|
|
pub fn id<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.id = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for id: {}", e));
|
|
self
|
|
}
|
|
pub fn name<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.name = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for name: {}", e));
|
|
self
|
|
}
|
|
pub fn owner<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<String>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.owner = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for owner: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkerTask> for super::WorkerTask {
|
|
type Error = String;
|
|
fn try_from(value: WorkerTask) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
id: value.id?,
|
|
name: value.name?,
|
|
owner: value.owner?,
|
|
})
|
|
}
|
|
}
|
|
|
|
pub struct WorkersResult {
|
|
workers: Result<Vec<super::Worker>, String>,
|
|
}
|
|
|
|
impl Default for WorkersResult {
|
|
fn default() -> Self {
|
|
Self {
|
|
workers: Err("no value supplied for workers".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorkersResult {
|
|
pub fn workers<T>(mut self, value: T) -> Self
|
|
where
|
|
T: std::convert::TryInto<Vec<super::Worker>>,
|
|
T::Error: std::fmt::Display,
|
|
{
|
|
self.workers = value
|
|
.try_into()
|
|
.map_err(|e| format!("error converting supplied value for workers: {}", e));
|
|
self
|
|
}
|
|
}
|
|
|
|
impl std::convert::TryFrom<WorkersResult> for super::WorkersResult {
|
|
type Error = String;
|
|
fn try_from(value: WorkersResult) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
workers: value.workers?,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[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};
|
|
///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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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: std::convert::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)),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub mod prelude {
|
|
pub use self::super::Client;
|
|
}
|