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