X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain.rs;fp=src%2Fmain.rs;h=60d072403a7b10f82d62987df69ab8b3052e1948;hb=d967084705e1d4f80a6a8b8ef4272989b14e2388;hp=08039fb26eb442810a7783296bae277554d5cf70;hpb=8ff916896124ea900ea2c6b66c87e6cc72ffe1eb;p=stakingWatchdog.git diff --git a/src/main.rs b/src/main.rs index 08039fb..60d0724 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ mod config; const FILE_CONF: &str = "config.ron"; const CHECK_PERIOD: Duration = Duration::from_secs(10); // 10 s. const PING_TIMEOUT: Duration = Duration::from_secs(10); // 10 s. +const NUMBER_SUCCESSIVE_ERRORS_SEND_EMAIL: i32 = 2; // Send an email after 2 successive errors. const EMAIL_RESEND_PERIOD: Duration = Duration::from_secs(2 * 60 * 60); // 2 h. const STATE_PRINT_PERIOD: Duration = Duration::from_secs(15 * 60); // 15 min. const BASE_URI: &str = "http://localhost:5052/eth/v1/"; @@ -45,7 +46,7 @@ fn main() -> Result<()> { let mut time_last_email_send = time::Instant::now() - EMAIL_RESEND_PERIOD; let mut time_last_state_printed = time::Instant::now() - STATE_PRINT_PERIOD; - let mut error_state = false; + let mut error_count = 0; // Number of successive errors. loop { let time_beginning_loop = time::Instant::now(); @@ -54,9 +55,11 @@ fn main() -> Result<()> { .as_ref() .and(check_alive_error_mutex.lock().unwrap().as_ref()) { - error_state = true; - println!("Error: {:?}", error); - if time::Instant::now() - time_last_email_send >= EMAIL_RESEND_PERIOD { + error_count += 1; + println!("Error (error_count={}): {:?}", error_count, error); + if error_count >= NUMBER_SUCCESSIVE_ERRORS_SEND_EMAIL + && time::Instant::now() - time_last_email_send >= EMAIL_RESEND_PERIOD + { // Send e-mail. println!("Sending email..."); match send_email( @@ -74,8 +77,8 @@ fn main() -> Result<()> { } } } else { - if error_state { - error_state = false; + if error_count > 0 { + error_count = 0; println!("End of erroneous state"); }