Skip to content

Commit

Permalink
fix: add health check file with 0 or 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Amninder Kaur committed Oct 13, 2023
1 parent 6107c18 commit a5a05c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target

/heathcheck


### Linux ###
Expand Down
1 change: 0 additions & 1 deletion How-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ All the required configurations for Chronos can be passed in environment variabl
| PG_PASSWORD|admin|True
| PG_DATABASE|chronos_db|True
| PG_POOL_SIZE|50|True
|NODE_ID|UUID|False
| DELAY_TIME|0|False
| RANDOMNESS_DELAY|100|False
| MONITOR_DB_POLL|5|False
Expand Down
25 changes: 22 additions & 3 deletions chronos_bin/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::kafka::consumer::KafkaConsumer;
use crate::kafka::producer::KafkaProducer;
use log::debug;
use std::sync::Arc;

use crate::message_processor::MessageProcessor;
use crate::message_receiver::MessageReceiver;
use crate::monitor::FailureDetector;
use crate::postgres::pg::Pg;
use log::debug;
use std::fs::{create_dir, read, remove_file, write};
use std::sync::Arc;

pub struct Runner {
pub consumer: Arc<KafkaConsumer>,
Expand Down Expand Up @@ -48,9 +48,28 @@ impl Runner {
message_receiver.run().await;
});

// check if healthcheck file exists in healthcheck dir
let healthcheck_file = "healthcheck/chronos_healthcheck";
let healthcheck_file_exists = read(healthcheck_file).is_ok();
if healthcheck_file_exists {
log::info!("healthcheck file exists");
let write_resp = write(healthcheck_file, b"1");
if write_resp.is_err() {
log::error!("error while writing to healthcheck file {:?}", write_resp);
}
} else if create_dir("healthcheck").is_ok() {
let write_resp = write(healthcheck_file, b"1");
if write_resp.is_err() {
log::error!("error while writing to healthcheck file {:?}", write_resp);
}
}
let future_tuple = futures::future::try_join3(monitor_handler, message_processor_handler, message_receiver_handler).await;
if future_tuple.is_err() {
log::error!("Chronos Stopping all threads {:?}", future_tuple);
let write_resp = write(healthcheck_file, b"0");
if write_resp.is_err() {
log::error!("error while writing to healthcheck file {:?}", write_resp);
}
}
}
}

0 comments on commit a5a05c4

Please sign in to comment.