|
|
@ -2,14 +2,45 @@ use u_lib::contracts::*; |
|
|
|
use warp::{ |
|
|
|
use warp::{ |
|
|
|
Rejection, |
|
|
|
Rejection, |
|
|
|
Reply, |
|
|
|
Reply, |
|
|
|
|
|
|
|
reply::with_status, |
|
|
|
|
|
|
|
http::StatusCode |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
use uuid::Uuid; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn report( |
|
|
|
|
|
|
|
msg: Message<'_, IterWrap<Vec<JobResult>>>, |
|
|
|
|
|
|
|
db: Storage) -> Result<impl Reply, Rejection> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
let results = msg.item.into_inner(); |
|
|
|
|
|
|
|
let mut storage = db.results().await; |
|
|
|
|
|
|
|
results.into_iter().for_each(|new_result| { |
|
|
|
|
|
|
|
match storage.get_mut(&new_result.id) { |
|
|
|
|
|
|
|
Some(v) => v.push(new_result), |
|
|
|
|
|
|
|
None => storage.insert(new_result.id, vec![new_result]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
Ok(with_status(warp::reply(), StatusCode::OK)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn get_job_results( |
|
|
|
|
|
|
|
uid: Uuid, |
|
|
|
|
|
|
|
db: Storage) -> Result<impl Reply, Rejection> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
let storage = db.results().await; |
|
|
|
|
|
|
|
match storage.get(&uid) { |
|
|
|
|
|
|
|
Some(v) => Ok(warp::reply::json( |
|
|
|
|
|
|
|
&Message::new(v.clone()) |
|
|
|
|
|
|
|
)), |
|
|
|
|
|
|
|
None => Err(warp::reject()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub async fn add_client( |
|
|
|
pub async fn add_client( |
|
|
|
msg: Message<'_, ClientInfo>, |
|
|
|
msg: Message<'_, ClientInfo>, |
|
|
|
db: Storage) -> Result<impl Reply, Rejection> |
|
|
|
db: Storage) -> Result<impl Reply, Rejection> |
|
|
|
{ |
|
|
|
{ |
|
|
|
let new_cli = msg.item; |
|
|
|
let new_cli = msg.item; |
|
|
|
let mut clients = db.lock().await; |
|
|
|
let mut clients = db.clients().await; |
|
|
|
if clients.contains_key(&new_cli.id) { |
|
|
|
if clients.contains_key(&new_cli.id) { |
|
|
|
Ok(warp::reply::json( |
|
|
|
Ok(warp::reply::json( |
|
|
|
&RawMsg("Already exist".to_string()).as_message() |
|
|
|
&RawMsg("Already exist".to_string()).as_message() |
|
|
@ -28,7 +59,7 @@ pub async fn add_client( |
|
|
|
pub async fn get_jobs( |
|
|
|
pub async fn get_jobs( |
|
|
|
db: Storage) -> Result<impl Reply, Rejection> |
|
|
|
db: Storage) -> Result<impl Reply, Rejection> |
|
|
|
{ |
|
|
|
{ |
|
|
|
let mut clients = db.lock().await; |
|
|
|
let mut clients = db.clients().await; |
|
|
|
let cli = clients.get_mut(&msg.id).unwrap(); |
|
|
|
let cli = clients.get_mut(&msg.id).unwrap(); |
|
|
|
cli.jobs.iter_mut().for_each(|job: &mut JobMeta| { |
|
|
|
cli.jobs.iter_mut().for_each(|job: &mut JobMeta| { |
|
|
|
if job.state == JobState::Queued { |
|
|
|
if job.state == JobState::Queued { |
|
|
@ -42,10 +73,10 @@ pub async fn get_jobs( |
|
|
|
|
|
|
|
|
|
|
|
pub async fn set_jobs( |
|
|
|
pub async fn set_jobs( |
|
|
|
uid: Option<Uuid>, |
|
|
|
uid: Option<Uuid>, |
|
|
|
msg: Message<'_, CollectionWrapper<JobMetaStorage>>, |
|
|
|
msg: Message<'_, IterWrap<JobMetaStorage>>, |
|
|
|
db: Storage) -> Result<impl Reply, Rejection> |
|
|
|
db: Storage) -> Result<impl Reply, Rejection> |
|
|
|
{ |
|
|
|
{ |
|
|
|
let mut clients = db.lock().await; |
|
|
|
let mut clients = db.clients().await; |
|
|
|
let cli = clients.get_mut(&uid.unwrap_or(msg.id)).unwrap(); |
|
|
|
let cli = clients.get_mut(&uid.unwrap_or(msg.id)).unwrap(); |
|
|
|
msg.item.0.into_iter().for_each(|(uuid, job)| { |
|
|
|
msg.item.0.into_iter().for_each(|(uuid, job)| { |
|
|
|
match cli.jobs.get_mut(&uuid) { |
|
|
|
match cli.jobs.get_mut(&uuid) { |
|
|
@ -57,13 +88,13 @@ pub async fn set_jobs( |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub async fn listing(db: Storage) -> Result<impl Reply, Rejection> { |
|
|
|
pub async fn ls(db: Storage) -> Result<impl Reply, Rejection> { |
|
|
|
let clients = db.lock().await; |
|
|
|
let clients = db.clients().await; |
|
|
|
let mut result: Vec<ClientInfo> = Vec::with_capacity(clients.len()); |
|
|
|
let mut result: Vec<ClientInfo> = Vec::with_capacity(clients.len()); |
|
|
|
for cli in clients.values() { |
|
|
|
for cli in clients.values() { |
|
|
|
result.push(cli.client_info.clone()); |
|
|
|
result.push(cli.client_info.clone()); |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(warp::reply::json( |
|
|
|
Ok(warp::reply::json( |
|
|
|
&CollectionWrapper(result).as_message() |
|
|
|
&IterWrap(result).as_message() |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |