From 689350aed53e397abd5af6af51063468907b2305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 10 Feb 2022 15:20:15 +0100 Subject: [PATCH] only return in progress jobs by default on /api/jobs --- src/routes.rs | 18 ++++++++++++++++-- src/util/jobs.rs | 10 +++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/routes.rs b/src/routes.rs index d64a182..13e28aa 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -559,10 +559,24 @@ pub async fn latest_files(state: web::Data) -> Result, +} + #[get("/api/jobs")] -pub async fn get_jobs(state: web::Data) -> Result { +pub async fn get_jobs( + state: web::Data, + web::Query(query): web::Query, +) -> Result { 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")] diff --git a/src/util/jobs.rs b/src/util/jobs.rs index 6d8f915..98fdc46 100644 --- a/src/util/jobs.rs +++ b/src/util/jobs.rs @@ -5,10 +5,10 @@ use uuid::Uuid; #[derive(Default, Serialize, Clone)] pub struct Job { - job_type: Option, - title: String, - progress: f32, - state: State, + pub job_type: Option, + 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 - ))) + ))); } }