File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ extern crate serde_json;
15
15
16
16
use std:: error:: Error ;
17
17
use std:: path:: PathBuf ;
18
+ use std:: sync:: Arc ;
19
+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
20
+
18
21
19
22
use chrono:: { DateTime , Utc } ;
20
23
use clap:: { Parser , Subcommand } ;
@@ -207,7 +210,14 @@ fn main() -> Result<(), Box<dyn Error>> {
207
210
}
208
211
209
212
fn daemon ( client : & AwClient ) -> Result < ( ) , Box < dyn Error > > {
210
- loop {
213
+ let running = Arc :: new ( AtomicBool :: new ( true ) ) ;
214
+ let r = running. clone ( ) ;
215
+
216
+ ctrlc:: set_handler ( move || {
217
+ r. store ( false , Ordering :: SeqCst ) ;
218
+ } ) ?;
219
+
220
+ while running. load ( Ordering :: SeqCst ) {
211
221
if let Err ( e) = daemon_sync_cycle ( client) {
212
222
error ! ( "Error during sync cycle: {}" , e) ;
213
223
// Re-throw the error
@@ -217,6 +227,9 @@ fn daemon(client: &AwClient) -> Result<(), Box<dyn Error>> {
217
227
info ! ( "Sync pass done, sleeping for 5 minutes" ) ;
218
228
std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 300 ) ) ;
219
229
}
230
+
231
+ info ! ( "Termination signal received, shutting down." ) ;
232
+ Ok ( ( ) )
220
233
}
221
234
222
235
fn daemon_sync_cycle ( client : & AwClient ) -> Result < ( ) , Box < dyn Error > > {
You can’t perform that action at this time.
0 commit comments