uuids, add jobs
This commit is contained in:
parent
416bdaecee
commit
817655ef7e
150
Cargo.lock
generated
150
Cargo.lock
generated
@ -8,6 +8,7 @@ dependencies = [
|
||||
"rocket_contrib",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -21,6 +22,12 @@ dependencies = [
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.0"
|
||||
@ -70,6 +77,15 @@ version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "cloudabi"
|
||||
version = "0.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cookie"
|
||||
version = "0.11.2"
|
||||
@ -145,6 +161,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-cprng"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-zircon"
|
||||
version = "0.3.3"
|
||||
@ -218,7 +240,7 @@ version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"autocfg 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -475,6 +497,121 @@ dependencies = [
|
||||
"proc-macro2 1.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7",
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core 0.4.2",
|
||||
"rand_hc",
|
||||
"rand_isaac",
|
||||
"rand_jitter",
|
||||
"rand_os",
|
||||
"rand_pcg",
|
||||
"rand_xorshift",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7",
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
dependencies = [
|
||||
"rand_core 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_isaac"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_jitter"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_core 0.4.2",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_os"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
|
||||
dependencies = [
|
||||
"cloudabi",
|
||||
"fuchsia-cprng",
|
||||
"libc",
|
||||
"rand_core 0.4.2",
|
||||
"rdrand",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_pcg"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7",
|
||||
"rand_core 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rdrand"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.56"
|
||||
@ -540,6 +677,7 @@ dependencies = [
|
||||
"rocket",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -739,6 +877,16 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.1.5"
|
||||
|
@ -12,7 +12,9 @@ rocket = "0.4.4"
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
|
||||
uuid = { version = "0.7", features = ["serde", "v4"] }
|
||||
|
||||
[dependencies.rocket_contrib]
|
||||
version = "0.4.4"
|
||||
default-features = false
|
||||
features = ["json"]
|
||||
features = ["json", "uuid"]
|
||||
|
@ -1,7 +1,14 @@
|
||||
let
|
||||
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
|
||||
nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
|
||||
rustNightlyChannel = (nixpkgs.rustChannelOf { date = "2020-03-24"; channel = "nightly"; }).rust;
|
||||
rustNightlyChannel = (nixpkgs.rustChannelOf { date = "2020-03-19"; channel = "nightly"; }).rust.override {
|
||||
extensions = [
|
||||
"rust-src"
|
||||
"rls-preview"
|
||||
"clippy-preview"
|
||||
"rustfmt-preview"
|
||||
];
|
||||
};
|
||||
rustStableChannel = nixpkgs.latest.rustChannels.stable.rust.override {
|
||||
extensions = [
|
||||
"rust-src"
|
||||
|
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)]
|
||||
|
Loading…
Reference in New Issue
Block a user