From 8ebc4abc195663dcba38d9dcf2c222a648ec3022 Mon Sep 17 00:00:00 2001 From: onyinyang Date: Thu, 7 Sep 2023 11:00:34 -0400 Subject: [PATCH] Minor formatting changes and last context read fix --- crates/lox-distributor/src/db_handler.rs | 4 ++-- crates/lox-distributor/src/main.rs | 7 +++---- crates/lox-distributor/src/resource_parser.rs | 5 ++++- crates/rdsys-backend-api/src/lib.rs | 10 +++++----- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/lox-distributor/src/db_handler.rs b/crates/lox-distributor/src/db_handler.rs index 149cb3d..26966fa 100644 --- a/crates/lox-distributor/src/db_handler.rs +++ b/crates/lox-distributor/src/db_handler.rs @@ -7,7 +7,7 @@ use sled::IVec; pub struct DB { db: sled::Db, - } +} impl DB { pub fn write_context(&mut self, context: lox_context::LoxServerContext) { @@ -115,7 +115,7 @@ fn compute_startdate_string(date_range_end: String) -> Option> { fn use_last_context(lox_db: sled::Db) -> lox_context::LoxServerContext { let ivec_context = lox_db.last().unwrap().unwrap(); - let ivec_date: String = serde_json::from_slice(&ivec_context.0).unwrap(); + let ivec_date: String = String::from_utf8(ivec_context.0.to_vec()).unwrap(); println!("Using last context with date: {:?}", ivec_date); serde_json::from_slice(&ivec_context.1).unwrap() } diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index 24c2582..0387a3f 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -121,7 +121,6 @@ async fn rdsys_request(rtype: ResourceInfo, tx: mpsc::Sender>) { .await .unwrap(); tx.send(resources).await.unwrap(); - sleep(Duration::from_secs(30)).await; } } @@ -136,7 +135,7 @@ async fn rdsys_bridge_parser( } } -// Parse Bridges receives a ResourceDiff from rdsys_sender and sends it to the +// Parse Bridges receives a Vec from rdsys_sender and sends it to the // Context Manager to be parsed and added to the BridgeDB async fn parse_bridges(rdsys_tx: mpsc::Sender, mut rx: mpsc::Receiver>) { loop { @@ -283,7 +282,7 @@ async fn main() { }); let (tx, rx) = mpsc::channel(32); - let rdsys_stream_handler = spawn(async { rdsys_stream(config.rtype, tx, kill_stream).await }); + let rdsys_request_handler = spawn(async { rdsys_stream(config.rtype, tx, kill_stream).await }); let rdsys_resource_receiver = spawn(async { rdsys_bridge_parser(rdsys_tx, rx, kill_parser).await }); @@ -313,7 +312,7 @@ async fn main() { eprintln!("server error: {}", e); } future::join_all([ - rdsys_stream_handler, + rdsys_request_handler, rdsys_resource_receiver, context_manager, shutdown_handler, diff --git a/crates/lox-distributor/src/resource_parser.rs b/crates/lox-distributor/src/resource_parser.rs index 2eeb5b2..09863ed 100644 --- a/crates/lox-distributor/src/resource_parser.rs +++ b/crates/lox-distributor/src/resource_parser.rs @@ -50,7 +50,10 @@ pub fn parse_into_buckets( let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET]; let mut leftovers: Vec = Vec::new(); for bridgeline in bridgelines.clone() { - println!("Added bridge with fingerprint: {:?}", bridgeline.uid_fingerprint); + println!( + "Added bridge with fingerprint: {:?}", + bridgeline.uid_fingerprint + ); if count < MAX_BRIDGES_PER_BUCKET { bucket[count] = bridgeline; count += 1; diff --git a/crates/rdsys-backend-api/src/lib.rs b/crates/rdsys-backend-api/src/lib.rs index 10b6087..f3aa8b3 100644 --- a/crates/rdsys-backend-api/src/lib.rs +++ b/crates/rdsys-backend-api/src/lib.rs @@ -262,7 +262,8 @@ pub async fn start_stream( Ok(ResourceStream::new(rx)) } -pub async fn request_resources( api_endpoint: String, +pub async fn request_resources( + api_endpoint: String, name: String, token: String, resource_types: Vec, @@ -283,7 +284,8 @@ pub async fn request_resources( api_endpoint: String, .header("Authorization", &auth_value) .body(json) .send() - .await.unwrap(); + .await + .unwrap(); match response.status() { reqwest::StatusCode::OK => { fetched_resources = match response.json::>().await { @@ -291,9 +293,7 @@ pub async fn request_resources( api_endpoint: String, Err(e) => Err(Error::Reqwest(e)), }; } - other => { - fetched_resources = Err(Error::String(other)) - } + other => fetched_resources = Err(Error::String(other)), }; fetched_resources }