11use std:: fs:: { self , File } ;
2- use std:: time:: { self , Duration } ;
2+ use std:: time:: { self , Duration , UNIX_EPOCH } ;
33
44use daemonize:: Daemonize ;
5+ use netpulse:: errors:: CheckFlagTypeConversionError ;
56use netpulse:: records:: { Check , CheckFlag } ;
67use netpulse:: store:: Store ;
78use 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
4143fn 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