refactor(shutdown): extract 4 identical Ctrl+C handlers into core/shutdown.rs
This commit is contained in:
@@ -4,26 +4,16 @@ pub mod config;
|
||||
pub mod cron;
|
||||
pub mod cursor;
|
||||
pub mod db;
|
||||
pub mod dependent_queue;
|
||||
pub mod error;
|
||||
pub mod events_db;
|
||||
pub mod file_history;
|
||||
pub mod lock;
|
||||
pub mod logging;
|
||||
pub mod metrics;
|
||||
pub mod note_parser;
|
||||
pub mod path_resolver;
|
||||
pub mod paths;
|
||||
pub mod payloads;
|
||||
pub mod project;
|
||||
pub mod references;
|
||||
pub mod shutdown;
|
||||
pub mod sync_run;
|
||||
pub mod time;
|
||||
pub mod timeline;
|
||||
pub mod timeline_collect;
|
||||
pub mod timeline_expand;
|
||||
pub mod timeline_seed;
|
||||
pub mod trace;
|
||||
|
||||
pub use config::Config;
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
/// Spawn a background task that listens for Ctrl+C.
|
||||
///
|
||||
/// First press: cancels `signal` and prints an interrupt message.
|
||||
/// Second press: force-exits with code 130.
|
||||
pub fn install_ctrl_c_handler(signal: ShutdownSignal) {
|
||||
tokio::spawn(async move {
|
||||
let _ = tokio::signal::ctrl_c().await;
|
||||
eprintln!("\nInterrupted, finishing current batch... (Ctrl+C again to force quit)");
|
||||
signal.cancel();
|
||||
let _ = tokio::signal::ctrl_c().await;
|
||||
std::process::exit(130);
|
||||
});
|
||||
}
|
||||
|
||||
/// A cooperative cancellation token for graceful shutdown.
|
||||
///
|
||||
/// Clone-able and cheaply checkable from any thread or async task.
|
||||
|
||||
Reference in New Issue
Block a user