only return in progress jobs by default on /api/jobs
parent
f0bd965111
commit
689350aed5
|
@ -559,10 +559,24 @@ pub async fn latest_files(state: web::Data<State>) -> Result<HttpResponse, Error
|
|||
Ok(HttpResponse::Ok().json(&files))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct JobsRequest {
|
||||
full: Option<String>,
|
||||
}
|
||||
|
||||
#[get("/api/jobs")]
|
||||
pub async fn get_jobs(state: web::Data<State>) -> Result<HttpResponse, Error> {
|
||||
pub async fn get_jobs(
|
||||
state: web::Data<State>,
|
||||
web::Query(query): web::Query<JobsRequest>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let jobs = state.job_container.read().unwrap().get_jobs();
|
||||
Ok(HttpResponse::Ok().json(&jobs))
|
||||
Ok(HttpResponse::Ok().json(if query.full.is_some() {
|
||||
jobs
|
||||
} else {
|
||||
jobs.into_iter()
|
||||
.filter(|(_, j)| matches!(j.state, crate::util::jobs::State::InProgress))
|
||||
.collect()
|
||||
}))
|
||||
}
|
||||
|
||||
#[get("/api/info")]
|
||||
|
|
|
@ -5,10 +5,10 @@ use uuid::Uuid;
|
|||
|
||||
#[derive(Default, Serialize, Clone)]
|
||||
pub struct Job {
|
||||
job_type: Option<JobType>,
|
||||
title: String,
|
||||
progress: f32,
|
||||
state: State,
|
||||
pub job_type: Option<JobType>,
|
||||
pub title: String,
|
||||
pub progress: f32,
|
||||
pub state: State,
|
||||
}
|
||||
|
||||
impl Job {
|
||||
|
@ -79,7 +79,7 @@ impl JobContainer {
|
|||
return Err(JobInProgessError(format!(
|
||||
"Job of type \"{}\" currently in progress.",
|
||||
job_type
|
||||
)))
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue