From 6a6a340618af58967941e9de1cf17c1d98045e9b Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 17 Jul 2024 22:29:54 +0200 Subject: [PATCH] fix: don't hook signal handler for cli tasks --- main.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/main.rs b/main.rs index 8dcc5c4..adbcf6a 100644 --- a/main.rs +++ b/main.rs @@ -167,21 +167,27 @@ async fn init(args: Args, config: upub::Config) { return; } + + let ctx = upub::Context::new(db, domain, config.clone()) + .await.expect("failed creating server context"); + + #[cfg(feature = "cli")] + if let Mode::Cli { command } = args.command { + cli::run(ctx, command) + .await.expect("failed running cli task"); + + return; + } + + + // register signal handler only for long-lasting modes, such as server or worker let (tx, rx) = tokio::sync::watch::channel(false); let signals = Signals::new([SIGTERM, SIGINT]).expect("failed registering signal handler"); let handle = signals.handle(); let signals_task = tokio::spawn(handle_signals(signals, tx)); let stop = CancellationToken(rx); - let ctx = upub::Context::new(db, domain, config.clone()) - .await.expect("failed creating server context"); - match args.command { - #[cfg(feature = "cli")] - Mode::Cli { command } => - cli::run(ctx, command) - .await.expect("failed running cli task"), - #[cfg(feature = "serve")] Mode::Serve { bind } => routes::serve(ctx, bind, stop) @@ -203,6 +209,8 @@ async fn init(args: Args, config: upub::Config) { Mode::Config => unreachable!(), #[cfg(feature = "migrate")] Mode::Migrate => unreachable!(), + #[cfg(feature = "cli")] + Mode::Cli { .. } => unreachable!(), } handle.close();