diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index 7c62334..20f642c 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -1,3 +1,4 @@ +use chrono::Utc; use futures::future; use futures::StreamExt; use hyper::{ @@ -199,19 +200,27 @@ async fn context_manager(mut context_rx: mpsc::Receiver) { for pt in gone_resources { println!("A NEW GONE RESOURCE: {:?}", pt); for resource in pt.1 { - let bridgeline = parse_resource(resource); - 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!( + // If resource last passed tests 3 hours ago, it should be replaced with a working + // resource and be removed from the bridgetable. If it has been gone for more than 7 hours, + // we should stop trying to remove it from the bridge table and assume it has successfully been + // removed already + if resource.last_passed < (Utc::now() - chrono::Duration::hours(3)) + || resource.last_passed > (Utc::now() - chrono::Duration::hours(7)) + { + let bridgeline = parse_resource(resource); + 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! : {:?}", bridgeline ); - context.new_unreplaced_bridge(bridgeline); + context.new_unreplaced_bridge(bridgeline); + } } } } diff --git a/crates/rdsys-backend-api/src/proto.rs b/crates/rdsys-backend-api/src/proto.rs index a6c8773..eb21b15 100644 --- a/crates/rdsys-backend-api/src/proto.rs +++ b/crates/rdsys-backend-api/src/proto.rs @@ -1,7 +1,7 @@ +use chrono::{offset::Utc, DateTime}; use serde::{Deserialize, Serialize}; use sha1::{Digest, Sha1}; use std::collections::HashMap; -use chrono::{DateTime, offset::Utc}; /// The body of the request for resources made to the rdsys backend #[derive(Serialize)]