Minor formatting changes and last context read fix

This commit is contained in:
onyinyang 2023-09-07 11:00:34 -04:00
parent a31ed0a4e5
commit 8ebc4abc19
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
4 changed files with 14 additions and 12 deletions

View File

@ -7,7 +7,7 @@ use sled::IVec;
pub struct DB { pub struct DB {
db: sled::Db, db: sled::Db,
} }
impl DB { impl DB {
pub fn write_context(&mut self, context: lox_context::LoxServerContext) { pub fn write_context(&mut self, context: lox_context::LoxServerContext) {
@ -115,7 +115,7 @@ fn compute_startdate_string(date_range_end: String) -> Option<DateTime<Utc>> {
fn use_last_context(lox_db: sled::Db) -> lox_context::LoxServerContext { fn use_last_context(lox_db: sled::Db) -> lox_context::LoxServerContext {
let ivec_context = lox_db.last().unwrap().unwrap(); 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); println!("Using last context with date: {:?}", ivec_date);
serde_json::from_slice(&ivec_context.1).unwrap() serde_json::from_slice(&ivec_context.1).unwrap()
} }

View File

@ -121,7 +121,6 @@ async fn rdsys_request(rtype: ResourceInfo, tx: mpsc::Sender<Vec<Resource>>) {
.await .await
.unwrap(); .unwrap();
tx.send(resources).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<Resource> from rdsys_sender and sends it to the
// Context Manager to be parsed and added to the BridgeDB // Context Manager to be parsed and added to the BridgeDB
async fn parse_bridges(rdsys_tx: mpsc::Sender<Command>, mut rx: mpsc::Receiver<Vec<Resource>>) { async fn parse_bridges(rdsys_tx: mpsc::Sender<Command>, mut rx: mpsc::Receiver<Vec<Resource>>) {
loop { loop {
@ -283,7 +282,7 @@ async fn main() {
}); });
let (tx, rx) = mpsc::channel(32); 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 = let rdsys_resource_receiver =
spawn(async { rdsys_bridge_parser(rdsys_tx, rx, kill_parser).await }); spawn(async { rdsys_bridge_parser(rdsys_tx, rx, kill_parser).await });
@ -313,7 +312,7 @@ async fn main() {
eprintln!("server error: {}", e); eprintln!("server error: {}", e);
} }
future::join_all([ future::join_all([
rdsys_stream_handler, rdsys_request_handler,
rdsys_resource_receiver, rdsys_resource_receiver,
context_manager, context_manager,
shutdown_handler, shutdown_handler,

View File

@ -50,7 +50,10 @@ pub fn parse_into_buckets(
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET]; let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
let mut leftovers: Vec<BridgeLine> = Vec::new(); let mut leftovers: Vec<BridgeLine> = Vec::new();
for bridgeline in bridgelines.clone() { 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 { if count < MAX_BRIDGES_PER_BUCKET {
bucket[count] = bridgeline; bucket[count] = bridgeline;
count += 1; count += 1;

View File

@ -262,7 +262,8 @@ pub async fn start_stream(
Ok(ResourceStream::new(rx)) Ok(ResourceStream::new(rx))
} }
pub async fn request_resources( api_endpoint: String, pub async fn request_resources(
api_endpoint: String,
name: String, name: String,
token: String, token: String,
resource_types: Vec<String>, resource_types: Vec<String>,
@ -283,7 +284,8 @@ pub async fn request_resources( api_endpoint: String,
.header("Authorization", &auth_value) .header("Authorization", &auth_value)
.body(json) .body(json)
.send() .send()
.await.unwrap(); .await
.unwrap();
match response.status() { match response.status() {
reqwest::StatusCode::OK => { reqwest::StatusCode::OK => {
fetched_resources = match response.json::<Vec<proto::Resource>>().await { fetched_resources = match response.json::<Vec<proto::Resource>>().await {
@ -291,9 +293,7 @@ pub async fn request_resources( api_endpoint: String,
Err(e) => Err(Error::Reqwest(e)), Err(e) => Err(Error::Reqwest(e)),
}; };
} }
other => { other => fetched_resources = Err(Error::String(other)),
fetched_resources = Err(Error::String(other))
}
}; };
fetched_resources fetched_resources
} }