Skip to content

Commit

Permalink
toII
Browse files Browse the repository at this point in the history
  • Loading branch information
SoloJacobs committed Dec 5, 2023
1 parent 3e5709a commit 17335d8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion v2/robotmk/src/bin/scheduler/internal_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion v2/robotmk/src/bin/scheduler/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
21 changes: 14 additions & 7 deletions v2/robotmk/src/bin/scheduler/scheduling/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Suite> = 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<Suite> = suites.to_vec();
Expand All @@ -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<Suite>) {
Expand Down
2 changes: 1 addition & 1 deletion v2/robotmk/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit 17335d8

Please sign in to comment.