From 2d1561ae9a0a2b58f7124347e8956cfe41124fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Herbel?= Date: Tue, 26 Nov 2024 15:11:08 +0100 Subject: [PATCH 1/2] Make handling of cancellation more consistent in `main::run`. Return `Terminate::Cancelled` and the actual main function do the rest. --- src/bin/scheduler/main.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/bin/scheduler/main.rs b/src/bin/scheduler/main.rs index 17ac859a..77d17eb2 100644 --- a/src/bin/scheduler/main.rs +++ b/src/bin/scheduler/main.rs @@ -51,8 +51,7 @@ fn run() -> Result<(), Terminate> { ); if global_config.cancellation_token.is_cancelled() { - info!("Terminated"); - return Ok(()); + return Err(Terminate::Cancelled); } if let Some(grace_period) = args.grace_period { @@ -70,8 +69,7 @@ fn run() -> Result<(), Terminate> { info!("Setup steps completed"); if global_config.cancellation_token.is_cancelled() { - info!("Terminated"); - return Ok(()); + return Err(Terminate::Cancelled); } info!("Starting environment building"); @@ -80,15 +78,14 @@ fn run() -> Result<(), Terminate> { info!("Environment building finished"); if global_config.cancellation_token.is_cancelled() { - info!("Terminated"); - return Ok(()); + return Err(Terminate::Cancelled); } info!("Starting plan scheduling"); write_phase(&SchedulerPhase::Scheduling, &global_config)?; scheduling::scheduler::run_plans_and_cleanup(&global_config, &plans); - info!("Terminated"); - Ok(()) + + Err(Terminate::Cancelled) } fn write_phase( From dd605c53ef7233dc36b2e8a6997292608a527415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Herbel?= Date: Fri, 22 Nov 2024 10:33:23 +0100 Subject: [PATCH 2/2] Scheduler main: Check for cancellation between base setup and setup steps Barely makes a difference but is the correct thing to do. --- src/bin/scheduler/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin/scheduler/main.rs b/src/bin/scheduler/main.rs index 77d17eb2..3b15648b 100644 --- a/src/bin/scheduler/main.rs +++ b/src/bin/scheduler/main.rs @@ -63,6 +63,10 @@ fn run() -> Result<(), Terminate> { setup::base_directories::setup(&global_config, &plans)?; info!("Base setup completed"); + if global_config.cancellation_token.is_cancelled() { + return Err(Terminate::Cancelled); + } + write_phase(&SchedulerPhase::Setup, &global_config)?; let (plans, setup_failures) = setup::steps::run::run(&global_config, plans)?; write_setup_failures(setup_failures.into_iter(), &global_config)?;