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/";
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();
.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(
}
}
} else {
- if error_state {
- error_state = false;
+ if error_count > 0 {
+ error_count = 0;
println!("End of erroneous state");
}