refactor(shutdown): extract 4 identical Ctrl+C handlers into core/shutdown.rs
This commit is contained in:
1998
src/app/handlers.rs
Normal file
1998
src/app/handlers.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,26 +4,16 @@ pub mod config;
|
|||||||
pub mod cron;
|
pub mod cron;
|
||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod dependent_queue;
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod events_db;
|
|
||||||
pub mod file_history;
|
pub mod file_history;
|
||||||
pub mod lock;
|
pub mod lock;
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
pub mod note_parser;
|
|
||||||
pub mod path_resolver;
|
pub mod path_resolver;
|
||||||
pub mod paths;
|
pub mod paths;
|
||||||
pub mod payloads;
|
|
||||||
pub mod project;
|
pub mod project;
|
||||||
pub mod references;
|
|
||||||
pub mod shutdown;
|
pub mod shutdown;
|
||||||
pub mod sync_run;
|
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod timeline;
|
|
||||||
pub mod timeline_collect;
|
|
||||||
pub mod timeline_expand;
|
|
||||||
pub mod timeline_seed;
|
|
||||||
pub mod trace;
|
pub mod trace;
|
||||||
|
|
||||||
pub use config::Config;
|
pub use config::Config;
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
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.
|
/// A cooperative cancellation token for graceful shutdown.
|
||||||
///
|
///
|
||||||
/// Clone-able and cheaply checkable from any thread or async task.
|
/// Clone-able and cheaply checkable from any thread or async task.
|
||||||
|
|||||||
3333
src/main.rs
3333
src/main.rs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user