Dont reepat healthcheck statuses

Only sends healthcheck statuses if they are different then the current value
This commit is contained in:
Joe Bellus 2022-02-15 10:19:13 -05:00
parent 04c2f37b60
commit 6d9d863039
2 changed files with 31 additions and 16 deletions

View File

@ -73,7 +73,6 @@ impl Handler<Event> for EventBroker {
type Result = ();
fn handle(&mut self, msg: Event, _ctx: &mut Self::Context) -> Self::Result {
tracing::info!("Event received");
for (_, ses) in self.sessions.iter() {
let _ = ses.addr.do_send(msg.clone());
}

View File

@ -99,13 +99,21 @@ async fn main() {
.await
{
Ok(res) if res.status() == 200 => {
st.healthcheck_status.lock().await.insert(app.id, true);
let _ = events::EventBroker::from_registry()
.send(events::Event::HealthcheckChange {
app_id: app.id,
alive: true,
})
.await;
if !st
.healthcheck_status
.lock()
.await
.get(&app.id)
.unwrap_or(&false)
{
st.healthcheck_status.lock().await.insert(app.id, true);
let _ = events::EventBroker::from_registry()
.send(events::Event::HealthcheckChange {
app_id: app.id,
alive: true,
})
.await;
}
}
Err(e) => {
tracing::warn!("Error performing healthcheck: {}", e);
@ -118,14 +126,22 @@ async fn main() {
.await;
}
Ok(res) => {
tracing::warn!("Non 200 status code: {}", res.status());
st.healthcheck_status.lock().await.insert(app.id, false);
let _ = events::EventBroker::from_registry()
.send(events::Event::HealthcheckChange {
app_id: app.id,
alive: false,
})
.await;
if st
.healthcheck_status
.lock()
.await
.get(&app.id)
.unwrap_or(&true)
{
tracing::warn!("Non 200 status code: {}", res.status());
st.healthcheck_status.lock().await.insert(app.id, false);
let _ = events::EventBroker::from_registry()
.send(events::Event::HealthcheckChange {
app_id: app.id,
alive: false,
})
.await;
}
}
}
}