Skip to content

Commit

Permalink
remove lock
Browse files Browse the repository at this point in the history
  • Loading branch information
SoloJacobs committed Dec 5, 2023
1 parent 0219ad2 commit 2be476a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 48 deletions.
8 changes: 1 addition & 7 deletions v2/robotmk/src/bin/scheduler/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub enum EnvironmentBuildStatusError {
#[derive(Serialize)]
pub struct SuiteExecutionReport {
pub suite_id: String,
pub outcome: ExecutionReport,
pub outcome: AttemptsOutcome,
}

impl WritePiggybackSection for SuiteExecutionReport {
Expand All @@ -107,12 +107,6 @@ impl WritePiggybackSection for SuiteExecutionReport {
}
}

#[derive(Serialize)]
pub enum ExecutionReport {
Executed(AttemptsOutcome),
AlreadyRunning,
}

#[derive(Serialize)]
pub struct AttemptsOutcome {
pub attempts: Vec<AttemptOutcome>,
Expand Down
2 changes: 1 addition & 1 deletion v2/robotmk/src/bin/scheduler/scheduling/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::logging::log_and_return_error;
use anyhow::{bail, Result};
use log::error;
use std::time::Duration;
use tokio::task::{JoinSet, spawn_blocking};
use tokio::task::{spawn_blocking, JoinSet};
use tokio::time::interval;

#[tokio::main]
Expand Down
42 changes: 2 additions & 40 deletions v2/robotmk/src/bin/scheduler/scheduling/suites.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::environment::ResultCode;
use crate::internal_config::Suite;
use crate::results::{
AttemptOutcome, AttemptsConfig, AttemptsOutcome, ExecutionReport, SuiteExecutionReport,
};
use crate::results::{AttemptOutcome, AttemptsConfig, AttemptsOutcome, SuiteExecutionReport};
use crate::rf::{rebot::Rebot, robot::Attempt};
use crate::sessions::session::{RunOutcome, RunSpec};

Expand All @@ -12,30 +10,12 @@ use chrono::Utc;
use log::{debug, error};
use robotmk::section::WritePiggybackSection;
use std::fs::create_dir_all;
use std::sync::{MutexGuard, TryLockError};

pub fn run_suite(suite: &Suite) -> Result<()> {
// We hold the lock as long as `_non_parallel_guard` is in scope
let _non_parallel_guard = try_acquire_suite_lock(suite).map_err(|err| {
let report = SuiteExecutionReport {
suite_id: suite.id.clone(),
outcome: ExecutionReport::AlreadyRunning,
};
report
.write(
&suite.results_file,
suite.host.clone(),
&suite.results_directory_locker,
)
.context("Reporting failure to acquire suite lock failed")
.err()
.unwrap_or(err)
})?;

debug!("Running suite {}", &suite.id);
let report = SuiteExecutionReport {
suite_id: suite.id.clone(),
outcome: ExecutionReport::Executed(produce_suite_results(suite)?),
outcome: produce_suite_results(suite)?,
};
report
.write(
Expand All @@ -49,24 +29,6 @@ pub fn run_suite(suite: &Suite) -> Result<()> {
Ok(())
}

fn try_acquire_suite_lock(suite: &Suite) -> Result<MutexGuard<usize>> {
match suite.parallelism_protection.try_lock() {
Ok(non_parallel_guard) => Ok(non_parallel_guard),
Err(try_lock_error) => match try_lock_error {
TryLockError::WouldBlock => {
bail!(
"Failed to acquire lock for suite {}, skipping this run",
suite.id
);
}
TryLockError::Poisoned(poison_error) => {
error!("Lock for suite {} poisoned, unpoisoning", suite.id);
Ok(poison_error.into_inner())
}
},
}
}

fn produce_suite_results(suite: &Suite) -> Result<AttemptsOutcome> {
let output_directory = suite
.working_directory
Expand Down

0 comments on commit 2be476a

Please sign in to comment.