Skip to content

Commit

Permalink
chore: add Monitor config
Browse files Browse the repository at this point in the history
  • Loading branch information
Amninder Kaur committed Sep 11, 2023
1 parent 74b4edb commit 77d02db
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
10 changes: 6 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ PG_POOL_SIZE=25
# CONFIG
RUST_LOG=info


#APP
DELAY_TIME=0
RANDOMNESS_DELAY=100
DB_POLL_INTERVAL=5
TIMING_ADVANCE=10
FAIL_DETECT_INTERVAL=10
MONITOR_DB_POLL=5
TIMING_ADVANCE=0
FAIL_DETECT_INTERVAL=500
MAX_RETRIES=3
PROCESSOR_DB_POLL=10
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ RUST_LOG=debug
#APP
DELAY_TIME=0
RANDOMNESS_DELAY=100
DB_POLL_INTERVAL=5
MONITOR_DB_POLL=5
TIMING_ADVANCE=0
FAIL_DETECT_INTERVAL=500
FAIL_DETECT_INTERVAL=500
MAX_RETRIES=3
PROCESSOR_DB_POLL=10
2 changes: 1 addition & 1 deletion How-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ All the required configurations for Chronos can be passed in environment variabl
| PG_POOL_SIZE|50|True
| DELAY_TIME|0|False
| RANDOMNESS_DELAY|100|False
| DB_POLL_INTERVAL|5|False
| MONITOR_DB_POLL|5|False
| TIMING_ADVANCE|0|False
| FAIL_DETECT_INTERVAL|500|False

Expand Down
4 changes: 2 additions & 2 deletions chronos_bin/src/monitor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::postgres::pg::Pg;
use crate::utils::config::ChronosConfig;
use chrono::{Duration as chrono_duration, Utc};
use chrono::Utc;
use std::sync::Arc;
use std::time::Duration;

Expand All @@ -13,7 +13,7 @@ impl FailureDetector {
pub async fn run(&self) {
println!("Monitoring On!");
loop {
let _ = tokio::time::sleep(Duration::from_secs(ChronosConfig::from_env().db_poll_interval)).await; // sleep for 10sec
let _ = tokio::time::sleep(Duration::from_secs(ChronosConfig::from_env().monitor_db_poll)).await; // sleep for 10sec

match &self
.data_store
Expand Down
11 changes: 8 additions & 3 deletions chronos_bin/src/utils/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[derive(Debug, Clone)]
pub struct ChronosConfig {
// pub random_delay: u64,
pub db_poll_interval: u64,
pub monitor_db_poll: u64,
pub processor_db_poll: u64,
pub time_advance: u64,
pub fail_detect_interval: u64,
}
Expand All @@ -10,10 +11,14 @@ impl ChronosConfig {
pub fn from_env() -> ChronosConfig {
ChronosConfig {
// random_delay: env_var!("RANDOMNESS_DELAY").parse().unwrap(),
db_poll_interval: std::env::var("DB_POLL_INTERVAL")
monitor_db_poll: std::env::var("MONITOR_DB_POLL")
.unwrap_or_else(|_| "5".to_string())
.parse()
.expect("Failed to parse DB_POLL_INTERVAL!!"),
.expect("Failed to parse MONITOR_DB_POLL!!"),
processor_db_poll: std::env::var("PROCESSOR_DB_POLL")
.unwrap_or_else(|_| "5".to_string())
.parse()
.expect("Failed to parse PROCESSOR_DB_POLL!!"),
time_advance: std::env::var("TIMING_ADVANCE")
.unwrap_or_else(|_| "0".to_string())
.parse()
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ services:
# App config (optional)
# DELAY_TIME: 0
# RANDOMNESS_DELAY: 100
# DB_POLL_INTERVAL: 5
# MONITOR_POLL_INTERVAL: 5
# TIMING_ADVANCE: 0
# FAIL_DETECT_INTERVAL: 500
depends_on:
Expand Down

0 comments on commit 77d02db

Please sign in to comment.