uuids, add jobs
This commit is contained in:
16
src/main.rs
16
src/main.rs
@@ -6,8 +6,8 @@ use rocket::response::status::NotFound;
|
||||
|
||||
use rocket_contrib::json::Json;
|
||||
use serde_json::Value;
|
||||
use rocket_contrib::uuid::Uuid;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Mutex;
|
||||
|
||||
mod workunit;
|
||||
@@ -42,7 +42,7 @@ fn request_job(shared: State<SharedState>) -> Result<Json<Value>, NotFound<Strin
|
||||
let mut list = shared.list.lock().unwrap().clone();
|
||||
|
||||
list.retain(|x| x.status == EStatus::Queued);
|
||||
list.sort_by(|a, b| b.length.cmp(&a.length));
|
||||
list.sort_by(|a, b| b.description.length.cmp(&a.description.length));
|
||||
|
||||
let job = list.get(0);
|
||||
|
||||
@@ -50,10 +50,10 @@ fn request_job(shared: State<SharedState>) -> Result<Json<Value>, NotFound<Strin
|
||||
}
|
||||
|
||||
#[get("/get_job/<id>")]
|
||||
fn get_job(id: u32, shared: State<SharedState>) -> Result<Json<Value>, NotFound<String>> {
|
||||
fn get_job(id: Uuid, shared: State<SharedState>) -> Result<Json<Value>, NotFound<String>> {
|
||||
let list = shared.list.lock().unwrap().clone();
|
||||
|
||||
let job = list.into_iter().find(|x| x.id == id).ok_or(NotFound(format!("Job not Found: {id}", id = id)));
|
||||
let job = list.into_iter().find(|x| x.id == *id).ok_or(NotFound(format!("Job not Found: {id}", id = id)));
|
||||
|
||||
match job {
|
||||
Ok(j) => Ok(Json(serde_json::to_value(&j).unwrap())),
|
||||
@@ -61,9 +61,11 @@ fn get_job(id: u32, shared: State<SharedState>) -> Result<Json<Value>, NotFound<
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/add_job")]
|
||||
fn add_job(shared: State<SharedState>) -> Result<String, std::io::Error> {
|
||||
shared.list.lock().unwrap().push(WUnit::new(2, "iduno", None, 10, workunit::EOptions::default()));
|
||||
#[post("/add_job", format = "json", data = "<message>")]
|
||||
fn add_job(message: Json<workunit::WDesc>, shared: State<SharedState>) -> Result<String, String> {
|
||||
println!("{:#?}", message);
|
||||
let job = message.into_inner();
|
||||
shared.list.lock().unwrap().push(WUnit::new(job));
|
||||
Ok(format!("{:#?}", shared))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,36 @@
|
||||
use std::path::PathBuf;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct WUnit {
|
||||
pub id: u32,
|
||||
pub id: Uuid,
|
||||
pub description: WDesc,
|
||||
pub status: EStatus
|
||||
}
|
||||
impl WUnit {
|
||||
pub fn new(description: WDesc) -> Self {
|
||||
WUnit {
|
||||
id: Uuid::new_v4(),
|
||||
description: description,
|
||||
status: EStatus::Queued
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct WDesc {
|
||||
pub file_url: String,
|
||||
pub priority: u16,
|
||||
pub length: u32,
|
||||
pub options: EOptions,
|
||||
pub status: EStatus
|
||||
}
|
||||
impl WUnit {
|
||||
pub fn new(id: u32, file_url: &str, priority: Option<u16>, length: u32, options: EOptions) -> Self {
|
||||
WUnit {
|
||||
id: id,
|
||||
impl WDesc {
|
||||
pub fn new(file_url: &str, priority: Option<u16>, length: u32, options: Option<EOptions>) -> Self {
|
||||
WDesc {
|
||||
file_url: file_url.to_string(),
|
||||
priority: priority.unwrap_or(0),
|
||||
length: length,
|
||||
options: options,
|
||||
status: EStatus::default()
|
||||
options: options.unwrap_or(EOptions::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +39,7 @@ impl WUnit {
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct EOptions {
|
||||
pub mode: EMode,
|
||||
pub resolution: Resolution,
|
||||
pub resolution: Option<Resolution>,
|
||||
pub color_depth: EColorDepth,
|
||||
pub enable_fwd_keyframe: bool,
|
||||
pub kf_min_dist: Option<u16>,
|
||||
@@ -39,7 +51,7 @@ impl Default for EOptions {
|
||||
fn default() -> Self {
|
||||
EOptions{
|
||||
mode: EMode::default(),
|
||||
resolution: Resolution::default(),
|
||||
resolution: Option::default(),
|
||||
color_depth: EColorDepth::default(),
|
||||
enable_fwd_keyframe: true,
|
||||
kf_min_dist: Option::default(),
|
||||
@@ -66,8 +78,8 @@ impl Default for EMode {
|
||||
|
||||
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Resolution {
|
||||
pub width: Option<u16>,
|
||||
pub height: Option<u16>
|
||||
pub width: u16,
|
||||
pub height: u16
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user