1+ use std:: env;
12use std:: io:: Error ;
23use std:: process:: Command ;
34use std:: sync:: Mutex ;
@@ -7,14 +8,29 @@ lazy_static::lazy_static! {
78 static ref DATABASE_SYNC_MUTEX : Mutex <( ) > = Mutex :: new( ( ) ) ;
89}
910const SLEEP_SECONDS : u16 = 5 ;
10- const SLEEP_DURATION : Duration = Duration :: from_secs ( SLEEP_SECONDS as u64 ) ;
1111
1212fn main ( ) -> Result < ( ) , Error > {
1313 thread:: spawn ( move || {
1414 sync_database ( ) ;
1515 } ) ;
1616 let mut iter: u16 = 0 ;
17- let update_on_iter = 300 / SLEEP_SECONDS ;
17+ let args: Vec < String > = env:: args ( ) . collect ( ) ;
18+ let mut interval_seconds = SLEEP_SECONDS ;
19+ let mut network_interval_seconds = 300 ;
20+ if args. len ( ) > 1 {
21+ for ( i, arg) in args. iter ( ) . enumerate ( ) {
22+ if arg == "--interval-seconds" && i + 1 < args. len ( ) {
23+ interval_seconds = args[ i + 1 ] . parse ( ) . unwrap ( ) ;
24+ } else if arg == "--network-interval-seconds" && i + 1 < args. len ( ) {
25+ network_interval_seconds = args[ i + 1 ] . parse ( ) . unwrap ( ) ;
26+ }
27+ }
28+ }
29+ let sleep_duration: Duration = Duration :: from_secs ( interval_seconds as u64 ) ;
30+ if ( interval_seconds == 0 ) || ( network_interval_seconds == 0 ) {
31+ panic ! ( "interval-seconds and network-interval-seconds must be greater than 0" ) ;
32+ }
33+ let update_on_iter = network_interval_seconds / interval_seconds;
1834 loop {
1935 if iter >= update_on_iter {
2036 sync_database ( ) ;
@@ -28,7 +44,7 @@ fn main() -> Result<(), Error> {
2844 println ! ( "{{\" text\" :\" {}\" ,\" tooltip\" :\" System updated\" ,\" class\" : \" updated\" ,\" alt\" :\" updated\" }}" , updates) ;
2945 }
3046 iter += 1 ;
31- std:: thread:: sleep ( SLEEP_DURATION ) ;
47+ std:: thread:: sleep ( sleep_duration ) ;
3248 }
3349}
3450
0 commit comments