only return in progress jobs by default on /api/jobs

feat/vaults
Tomáš Mládek 2022-02-10 15:20:15 +01:00
parent f0bd965111
commit 689350aed5
No known key found for this signature in database
GPG Key ID: 65E225C8B3E2ED8A
2 changed files with 21 additions and 7 deletions

View File

@ -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")]

View File

@ -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
)))
)));
}
}