diff --git a/src/main.rs b/src/main.rs index a77cf81..4dacef5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; + +use serde::{Serialize, Deserialize}; + use rocket::State; use rocket::response::status::NotFound; use rocket::Data; @@ -19,7 +22,7 @@ mod workunit; use workunit::WUnit; use workunit::EStatus; -const VERSION: &str = "0.11.0"; +const VERSION: &str = "0.12.0"; #[derive(Default, Debug)] struct SharedState { @@ -38,6 +41,42 @@ fn version() -> &'static str { VERSION } +#[get("/stats")] +fn get_stats(shared: State) -> Json { + + #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] + struct Stats { + queued: u32, + progress: u32, + completed: u32, + cancelled: u32, + error: u32, + length: u32 + }; + + let list = shared.jobs.lock().unwrap().clone(); + let mut stats: Stats = Stats { + queued: 0, + progress: 0, + completed: 0, + cancelled: 0, + error: 0, + length: 999 + }; + + for job in list.values() { + match &job.status { + EStatus::Queued => stats.queued += 1, + EStatus::Reserved(a) => stats.progress += 1, + EStatus::Completed(a) => stats.completed += 1, + EStatus::Cancelled => stats.cancelled += 1, + EStatus::Error(a) => stats.error += 1 + }; + } + + Json(serde_json::to_value(&stats).unwrap()) +} + #[get("/get_jobs")] fn get_jobs(shared: State) -> Json { let list = shared.jobs.lock().unwrap().clone(); diff --git a/src/static/client.sh b/src/static/client.sh index d1ffe51..732d0f3 100755 --- a/src/static/client.sh +++ b/src/static/client.sh @@ -4,7 +4,7 @@ set -euo pipefail IFS=$'\n\t' base_url="$1" -version="0.11.0" +version="0.12.0" while true; do sleep 30 @@ -73,7 +73,7 @@ while true; do etype=`echo $job | jq -r '.description.options | keys | .[]'` - if [$etype != "FFMPEG"] && [$etype != "AOMENC" ]; then + if [ $etype != "FFMPEG" ] && [ $etype != "AOMENC" ]; then echo "That's not a valid encoder!! Are you being attacked?" fi