Skip to content

Commit 05ebf25

Browse files
committed
refactor(daemon): mock daemon has failing checks sometimes now
1 parent e722a6d commit 05ebf25

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/bins/netpulsed.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::fs::{self, File};
2-
use std::time::{self, Duration};
2+
use std::time::{self, Duration, UNIX_EPOCH};
33

44
use daemonize::Daemonize;
5+
use netpulse::errors::CheckFlagTypeConversionError;
56
use netpulse::records::{Check, CheckFlag};
67
use netpulse::store::Store;
78
use netpulse::{DAEMON_LOG_ERR, DAEMON_LOG_INF};
@@ -26,7 +27,7 @@ fn main() {
2627
.stderr(errfile)
2728
.umask(0o027); // rwxr-x---
2829

29-
eprintln!("daemon setup done");
30+
println!("daemon setup done");
3031

3132
match daemonize.start() {
3233
Ok(_) => daemon(),
@@ -38,16 +39,25 @@ fn main() {
3839
eprintln!("end?")
3940
}
4041

42+
// TODO: better error handling, keep going even if everything goes boom
4143
fn daemon() {
4244
println!("starting daemon...");
4345
let mut store = Store::load_or_create().expect("boom");
4446
loop {
47+
let time = time::SystemTime::now();
48+
println!("making a check...");
4549
store.add_check(Check::new(
46-
time::SystemTime::now(),
47-
CheckFlag::Success,
50+
time,
51+
if time.duration_since(UNIX_EPOCH).unwrap().as_secs() % 10 == 0 {
52+
CheckFlag::Timeout | CheckFlag::TypePing
53+
} else {
54+
CheckFlag::Success.into()
55+
},
4856
None,
4957
));
58+
println!("saving...");
5059
store.save().expect("could not save");
60+
println!("done! sleeping...");
5161
std::thread::sleep(Duration::from_secs(5));
5262
}
5363
}

0 commit comments

Comments
 (0)