projects
/
stakingWatchdog.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8ff9168
)
Send email only if there are two successive errors
author
Greg Burri
<greg.burri@gmail.com>
Fri, 24 Nov 2023 08:17:48 +0000
(09:17 +0100)
committer
Greg Burri
<greg.burri@gmail.com>
Fri, 24 Nov 2023 08:17:48 +0000
(09:17 +0100)
src/main.rs
patch
|
blob
|
history
diff --git
a/src/main.rs
b/src/main.rs
index
08039fb
..
60d0724
100644
(file)
--- 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 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/";
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 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();
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())
{
.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(
// Send e-mail.
println!("Sending email...");
match send_email(
@@
-74,8
+77,8
@@
fn main() -> Result<()> {
}
}
} else {
}
}
} else {
- if error_
state
{
- error_
state = false
;
+ if error_
count > 0
{
+ error_
count = 0
;
println!("End of erroneous state");
}
println!("End of erroneous state");
}