diff --git a/v2/robotmk/src/bin/scheduler/internal_config.rs b/v2/robotmk/src/bin/scheduler/internal_config.rs index 563043aa..a91d3c08 100644 --- a/v2/robotmk/src/bin/scheduler/internal_config.rs +++ b/v2/robotmk/src/bin/scheduler/internal_config.rs @@ -26,7 +26,7 @@ pub struct Suite { pub id: String, pub working_directory: Utf8PathBuf, pub results_file: Utf8PathBuf, - pub execution_interval_seconds: u32, + pub execution_interval_seconds: u64, pub timeout: u64, pub robot: Robot, pub environment: Environment, diff --git a/v2/robotmk/src/bin/scheduler/results.rs b/v2/robotmk/src/bin/scheduler/results.rs index c6d1b198..2617a61e 100644 --- a/v2/robotmk/src/bin/scheduler/results.rs +++ b/v2/robotmk/src/bin/scheduler/results.rs @@ -145,7 +145,7 @@ pub struct RebotResult { #[derive(Serialize)] pub struct AttemptsConfig { - pub interval: u32, + pub interval: u64, pub timeout: u64, pub n_attempts_max: usize, } diff --git a/v2/robotmk/src/bin/scheduler/scheduling/scheduler.rs b/v2/robotmk/src/bin/scheduler/scheduling/scheduler.rs index 8be420a2..c0751a0b 100644 --- a/v2/robotmk/src/bin/scheduler/scheduling/scheduler.rs +++ b/v2/robotmk/src/bin/scheduler/scheduling/scheduler.rs @@ -9,15 +9,15 @@ use log::error; use std::thread::{sleep, spawn}; use std::time::Duration; use tokio::task::spawn_blocking; +use tokio::time::interval; -pub fn run_suites_and_cleanup(global_config: &GlobalConfig, suites: &[Suite]) -> Result<()> { +#[tokio::main] +pub async fn run_suites_and_cleanup(global_config: &GlobalConfig, suites: &[Suite]) -> Result<()> { let mut scheduler = Scheduler::new(); let suites_for_scheduling: Vec = suites.to_vec(); for suite in suites_for_scheduling { - scheduler - .every(suite.execution_interval_seconds.seconds()) - .run(move || run_suite_in_new_thread(suite.clone())); + tokio::spawn(run_scheduler(suite)); } let suites_for_cleanup: Vec = suites.to_vec(); @@ -36,9 +36,16 @@ pub fn run_suites_and_cleanup(global_config: &GlobalConfig, suites: &[Suite]) -> } } -#[tokio::main] -async fn run_suite_in_new_thread(suite: Suite) { - spawn_blocking(move || run_suite(&suite).map_err(log_and_return_error)); +async fn run_scheduler(suite: Suite) { + let mut clock = interval(Duration::from_secs(suite.execution_interval_seconds)); + loop { + let suite = suite.clone(); + tokio::select! { + _ = clock.tick() => { } + _ = suite.cancellation_token.cancelled() => { return } + }; + spawn_blocking(move || run_suite(&suite).map_err(log_and_return_error)); + } } fn run_cleanup_working_directories_in_new_thread(suites: Vec) { diff --git a/v2/robotmk/src/config.rs b/v2/robotmk/src/config.rs index 27e59965..686d42e0 100644 --- a/v2/robotmk/src/config.rs +++ b/v2/robotmk/src/config.rs @@ -38,7 +38,7 @@ pub struct RobotFrameworkConfig { pub struct ExecutionConfig { pub n_attempts_max: usize, pub retry_strategy: RetryStrategy, - pub execution_interval_seconds: u32, + pub execution_interval_seconds: u64, pub timeout: u64, }