use super::ResponseContent;
use super::{ContentType, Error, configuration};
use crate::models;
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CompleteJobError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateJobError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status422(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateJobsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteJobError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteJobsError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetJobError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListJobsError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ManageStatusChangeError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RetryJobError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status422(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum StartJobError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateJobError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
pub fn complete_job(
configuration: &configuration::Configuration,
id: i64,
status: models::JobStatus,
run_id: i64,
result_model: models::ResultModel,
) -> Result<models::JobModel, Error<CompleteJobError>> {
let p_path_id = id;
let p_path_status = status;
let p_path_run_id = run_id;
let p_body_result_model = result_model;
let uri_str = format!(
"{}/jobs/{id}/complete_job/{status}/{run_id}",
configuration.base_path,
id = p_path_id,
status = p_path_status,
run_id = p_path_run_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
req_builder = req_builder.json(&p_body_result_model);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::JobModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::JobModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<CompleteJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn create_job(
configuration: &configuration::Configuration,
job_model: models::JobModel,
) -> Result<models::JobModel, Error<CreateJobError>> {
let p_body_job_model = job_model;
let uri_str = format!("{}/jobs", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
req_builder = req_builder.json(&p_body_job_model);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::JobModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::JobModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<CreateJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn create_jobs(
configuration: &configuration::Configuration,
jobs_model: models::JobsModel,
) -> Result<models::CreateJobsResponse, Error<CreateJobsError>> {
let p_body_jobs_model = jobs_model;
let uri_str = format!("{}/bulk_jobs", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
req_builder = req_builder.json(&p_body_jobs_model);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::CreateJobsResponse`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::CreateJobsResponse`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<CreateJobsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn delete_job(
configuration: &configuration::Configuration,
id: i64,
) -> Result<models::JobModel, Error<DeleteJobError>> {
let p_path_id = id;
let uri_str = format!("{}/jobs/{id}", configuration.base_path, id = p_path_id);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::JobModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::JobModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<DeleteJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn delete_jobs(
configuration: &configuration::Configuration,
workflow_id: i64,
) -> Result<models::DeleteCountResponse, Error<DeleteJobsError>> {
let p_query_workflow_id = workflow_id;
let uri_str = format!("{}/jobs", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
req_builder = req_builder.query(&[("workflow_id", &p_query_workflow_id.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::DeleteCountResponse`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::DeleteCountResponse`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<DeleteJobsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn get_job(
configuration: &configuration::Configuration,
id: i64,
) -> Result<models::JobModel, Error<GetJobError>> {
let p_path_id = id;
let uri_str = format!("{}/jobs/{id}", configuration.base_path, id = p_path_id);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::JobModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::JobModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<GetJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn list_jobs(
configuration: &configuration::Configuration,
workflow_id: i64,
status: Option<models::JobStatus>,
needs_file_id: Option<i64>,
upstream_job_id: Option<i64>,
offset: Option<i64>,
limit: Option<i64>,
sort_by: Option<&str>,
reverse_sort: Option<bool>,
include_relationships: Option<bool>,
active_compute_node_id: Option<i64>,
) -> Result<models::ListJobsResponse, Error<ListJobsError>> {
let p_query_workflow_id = workflow_id;
let p_query_status = status;
let p_query_needs_file_id = needs_file_id;
let p_query_upstream_job_id = upstream_job_id;
let p_query_offset = offset;
let p_query_limit = limit;
let p_query_sort_by = sort_by;
let p_query_reverse_sort = reverse_sort;
let p_query_include_relationships = include_relationships;
let p_query_active_compute_node_id = active_compute_node_id;
let uri_str = format!("{}/jobs", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("workflow_id", &p_query_workflow_id.to_string())]);
if let Some(ref param_value) = p_query_status {
req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_needs_file_id {
req_builder = req_builder.query(&[("needs_file_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_upstream_job_id {
req_builder = req_builder.query(&[("upstream_job_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_by {
req_builder = req_builder.query(&[("sort_by", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_reverse_sort {
req_builder = req_builder.query(&[("reverse_sort", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_include_relationships {
req_builder = req_builder.query(&[("include_relationships", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_active_compute_node_id {
req_builder = req_builder.query(&[("active_compute_node_id", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ListJobsResponse`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::ListJobsResponse`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<ListJobsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn manage_status_change(
configuration: &configuration::Configuration,
id: i64,
status: models::JobStatus,
run_id: i64,
) -> Result<models::JobModel, Error<ManageStatusChangeError>> {
let p_path_id = id;
let p_path_status = status;
let p_path_run_id = run_id;
let uri_str = format!(
"{}/jobs/{id}/manage_status_change/{status}/{run_id}",
configuration.base_path,
id = p_path_id,
status = p_path_status,
run_id = p_path_run_id
);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::JobModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::JobModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<ManageStatusChangeError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn retry_job(
configuration: &configuration::Configuration,
id: i64,
run_id: i64,
max_retries: i32,
) -> Result<models::JobModel, Error<RetryJobError>> {
let p_path_id = id;
let p_path_run_id = run_id;
let p_query_max_retries = max_retries;
let uri_str = format!(
"{}/jobs/{id}/retry/{run_id}",
configuration.base_path,
id = p_path_id,
run_id = p_path_run_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("max_retries", &p_query_max_retries.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::JobModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::JobModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<RetryJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn start_job(
configuration: &configuration::Configuration,
id: i64,
run_id: i64,
compute_node_id: i64,
) -> Result<models::JobModel, Error<StartJobError>> {
let p_path_id = id;
let p_path_run_id = run_id;
let p_path_compute_node_id = compute_node_id;
let uri_str = format!(
"{}/jobs/{id}/start_job/{run_id}/{compute_node_id}",
configuration.base_path,
id = p_path_id,
run_id = p_path_run_id,
compute_node_id = p_path_compute_node_id
);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::JobModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::JobModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<StartJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn update_job(
configuration: &configuration::Configuration,
id: i64,
job_model: models::JobModel,
) -> Result<models::JobModel, Error<UpdateJobError>> {
let p_path_id = id;
let p_body_job_model = job_model;
let uri_str = format!("{}/jobs/{id}", configuration.base_path, id = p_path_id);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
req_builder = req_builder.json(&p_body_job_model);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::JobModel`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::JobModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<UpdateJobError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}