Skip to content

Commit

Permalink
Merge pull request #208 from samply/fix/timeout-time
Browse files Browse the repository at this point in the history
fix: Better timout timings
  • Loading branch information
lablans authored Aug 12, 2024
2 parents 5b5d67d + 7920fef commit 0d0042a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions broker/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ pub struct Health {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProxyStatus {
last_active: SystemTime,
last_connect: SystemTime,
last_disconnect: Option<SystemTime>,
#[serde(skip)]
connections: u8,
}
Expand All @@ -68,18 +69,27 @@ impl ProxyStatus {
}

pub fn disconnect(&mut self) {
self.last_disconnect = Some(SystemTime::now());
self.connections -= 1;
}

pub fn connect(&mut self) {
self.connections += 1;
self.last_active = SystemTime::now();
self.last_connect = SystemTime::now();
}

pub fn _last_seen(&self) -> SystemTime {
if self.online() {
SystemTime::now()
} else {
self.last_disconnect.expect("Should always exist as the proxy is not online")
}
}
}

impl ProxyStatus {
pub fn new() -> ProxyStatus {
ProxyStatus { last_active: SystemTime::now(), connections: 1 }
ProxyStatus { last_connect: SystemTime::now(), connections: 1, last_disconnect: None }
}
}

Expand Down

0 comments on commit 0d0042a

Please sign in to comment.