Add time check to gone resource handling

This commit is contained in:
onyinyang 2023-06-14 16:59:50 -04:00
parent d1710d2f80
commit 2e4090e21c
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 20 additions and 11 deletions

View File

@ -1,3 +1,4 @@
use chrono::Utc;
use futures::future; use futures::future;
use futures::StreamExt; use futures::StreamExt;
use hyper::{ use hyper::{
@ -199,19 +200,27 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
for pt in gone_resources { for pt in gone_resources {
println!("A NEW GONE RESOURCE: {:?}", pt); println!("A NEW GONE RESOURCE: {:?}", pt);
for resource in pt.1 { for resource in pt.1 {
let bridgeline = parse_resource(resource); // If resource last passed tests 3 hours ago, it should be replaced with a working
println!("BridgeLine to be replaced: {:?}", bridgeline); // resource and be removed from the bridgetable. If it has been gone for more than 7 hours,
let res = context.replace_with_new(bridgeline); // we should stop trying to remove it from the bridge table and assume it has successfully been
if res { // removed already
println!("BridgeLine successfully replaced: {:?}", bridgeline); if resource.last_passed < (Utc::now() - chrono::Duration::hours(3))
} else { || resource.last_passed > (Utc::now() - chrono::Duration::hours(7))
// Add the bridge to the list of unreplaced bridges in the Lox context and try {
// again to replace at the next update (nothing changes in the Lox Authority) let bridgeline = parse_resource(resource);
println!( println!("BridgeLine to be replaced: {:?}", bridgeline);
let res = context.replace_with_new(bridgeline);
if res {
println!("BridgeLine successfully replaced: {:?}", bridgeline);
} else {
// Add the bridge to the list of unreplaced bridges in the Lox context and try
// again to replace at the next update (nothing changes in the Lox Authority)
println!(
"'Gone' BridgeLine NOT replaced, saved for next update! : {:?}", "'Gone' BridgeLine NOT replaced, saved for next update! : {:?}",
bridgeline bridgeline
); );
context.new_unreplaced_bridge(bridgeline); context.new_unreplaced_bridge(bridgeline);
}
} }
} }
} }

View File

@ -1,7 +1,7 @@
use chrono::{offset::Utc, DateTime};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sha1::{Digest, Sha1}; use sha1::{Digest, Sha1};
use std::collections::HashMap; use std::collections::HashMap;
use chrono::{DateTime, offset::Utc};
/// The body of the request for resources made to the rdsys backend /// The body of the request for resources made to the rdsys backend
#[derive(Serialize)] #[derive(Serialize)]