Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
WIP #60 fixup terminate early
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjabear committed Sep 28, 2016
1 parent 2cc42af commit 4ca9d42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 8 additions & 9 deletions src/factotum/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,12 @@ pub fn execute_factfile(factfile:&Factfile, start_from:Option<String>) -> TaskLi
if task_group[idx].task_spec.on_result.terminate_job.contains(&task_result.return_code) {
// if the return code is in the terminate early list, prune the sub-tree (set to skipped) return early term
task_group[idx].state = State::SUCCESS_NOOP;
terminate_job_please = true;
} else if task_group[idx].task_spec.on_result.continue_job.contains(&task_result.return_code) {
// if the return code is in the continue list, return success
task_group[idx].state = State::SUCCESS;
} else {
// if the return code is not in either list, prune the sub-tree (set to skipped) and return error


let expected_codes = task_group[idx].task_spec.on_result.continue_job.iter()
.map(|code| code.to_string())
.collect::<Vec<String>>()
Expand All @@ -151,9 +150,11 @@ pub fn execute_factfile(factfile:&Factfile, start_from:Option<String>) -> TaskLi
task_result.return_code,
expected_codes);
task_group[idx].state = State::FAILED(err_msg);
task_failed = true;
}

task_group[idx].run_result = Some(task_result);


// if terminate_job_codes.contains(&return_code) {
// (TaskResult::TerminateJobPlease(return_code, run_duration), task_stdout_opt, task_stderr_opt)
Expand Down Expand Up @@ -204,14 +205,12 @@ pub fn execute_factfile(factfile:&Factfile, start_from:Option<String>) -> TaskLi
// }
}

// match (terminate_job_please, task_failed) {
// (_, true) => { return ExecutionResult::AbnormalTermination(drain_values(task_results, &tasks)); },
// (true, false) => { return ExecutionResult::EarlyFinishOk(drain_values(task_results, &tasks)); },
// _ => {}
// }
if terminate_job_please || task_failed {
break;
}

}

// ExecutionResult::AllTasksComplete(drain_values(task_results, &tasks))
tasklist
}

Expand Down Expand Up @@ -255,7 +254,7 @@ pub fn execute_factfile(factfile:&Factfile, start_from:Option<String>) -> TaskLi
// }
// }

fn format_args(command:&str, args:&Vec<String>) -> String {
pub fn format_args(command:&str, args:&Vec<String>) -> String {
let arg_str = args.iter()
.map(|s| format!("\"{}\"", s))
.collect::<Vec<String>>()
Expand Down
17 changes: 12 additions & 5 deletions src/factotum/executor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ fn get_task_execution_list_good() {
vec!["potato"],
vec!["chicken"] ];

let actual:Vec<Vec<String>> = tl.tasks
.iter()
.map(|task_group| task_group.iter().map(|task| task.name.clone()).collect())
.collect();
let actual:Vec<Vec<String>> = tl.tasks.iter()
.map(|task_group| task_group.iter().map(|task| task.name.clone()).collect())
.collect();

assert_eq!(actual, expected);

Expand All @@ -69,5 +68,13 @@ fn get_task_execution_list_good_reduced() {

let tl = get_task_execution_list(&ff, Some("potato".to_string()));
assert!(tl.tasks[0].len()==1);
// assert_eq!(tl.get_descendants("potato"), vec!["chicken"]);
assert_eq!(tl.get_descendants("potato"), vec!["chicken"]);
}

#[test]
fn get_formatted_args() {
let args_list = format_args("echo", &vec!["hello".to_string(),
"world".to_string(),
"abc abc".to_string()]);
assert_eq!(args_list, "echo \"hello\" \"world\" \"abc abc\"");
}

0 comments on commit 4ca9d42

Please sign in to comment.