Skip to content

Commit

Permalink
Merge pull request #68 from kdesjard/fix_err_w_code_output
Browse files Browse the repository at this point in the history
  • Loading branch information
genedna authored Aug 26, 2024
2 parents 81eb85c + 76fb8b8 commit 62a6d11
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/engine/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use tokio::task::JoinHandle;
///
/// The execution process of Dag is roughly as follows:
/// - The user gives a list of tasks `tasks`. These tasks can be parsed from configuration files, or provided
/// by user programming implementations.
/// by user programming implementations.
/// - Internally generate `Graph` based on task dependencies, and generate execution sequences based on `rely_graph`.
/// - The task is scheduled to start executing asynchronously.
/// - The task will wait to get the result `execute_states` generated by the execution of the predecessor task.
/// - If the result of the predecessor task can be obtained, check the continuation status `can_continue`, if it
/// is true, continue to execute the defined logic, if it is false, trigger `handle_error`, and cancel the
/// execution of the subsequent task.
/// is true, continue to execute the defined logic, if it is false, trigger `handle_error`, and cancel the
/// execution of the subsequent task.
/// - After all tasks are executed, set the continuation status to false, which means that the tasks of the dag
/// cannot be scheduled for execution again.
/// cannot be scheduled for execution again.
///
/// # Example
/// ```rust
Expand Down Expand Up @@ -370,7 +370,7 @@ impl Dag {
if out.is_err() {
let error = out.get_err().unwrap_or("".to_string());
error!(
"Execution failed [name: {}, id: {}]\nerr: {}",
"Execution failed [name: {}, id: {}] - {}",
task_name, task_id, error
);
execute_state.set_output(out);
Expand Down
2 changes: 1 addition & 1 deletion src/task/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Complex for CommandAction {
}
});

log::debug!("cmd: {:?}, args: {:?}", cmd.get_program(), args);
log::info!("cmd: {:?}, args: {:?}", cmd.get_program(), args);
let out = match cmd.args(args).output() {
Ok(o) => o,
Err(e) => {
Expand Down
9 changes: 3 additions & 6 deletions src/task/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,9 @@ impl Output {
match self {
Self::Out(_) => None,
Self::Err(err) => Some(err.to_string()),
Self::ErrWithExitCode(_, err) => {
if let Some(e) = err {
Some(e.get::<String>()?.to_string())
} else {
None
}
Self::ErrWithExitCode(code, _) => {
let error_code = code.map_or("".to_string(), |v| v.to_string());
Some(format!("code: {error_code}"))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub trait Parser {
/// Parameter Description:
/// - file: path information of the configuration file
/// - specific_actions: When parsing the configuration file, the specific execution logic
/// of some tasks does not need to be specified in the configuration file, but is given
/// through this map. In the map's key-value pair, the key represents the unique identifier
/// of the task in the task's configuration file, and the value represents the execution
/// logic given by the user.
/// of some tasks does not need to be specified in the configuration file, but is given
/// through this map. In the map's key-value pair, the key represents the unique identifier
/// of the task in the task's configuration file, and the value represents the execution
/// logic given by the user.
///
/// Return value description:
/// If an error is encountered during the parsing process, the return result is ParserError.
Expand Down
20 changes: 20 additions & 0 deletions tests/dag_job_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,23 @@ fn task_failed_execute() {
fn task_keep_going() {
test_dag(true, Some(8));
}

#[test]
fn error_with_exitcode() {
let mut job = Dag::with_yaml("tests/config/error_with_exitcode.yaml", HashMap::new()).unwrap();
_ = job.start();
// hacky as ID_ALLOCATOR is static, so I don't know which id to use
// to get the output of this single task
match &job.get_outputs()[job.get_outputs().keys().next().unwrap()] {
dagrs::Output::ErrWithExitCode(code, content) => {
if let Some(output) = content {
let (stdout, _stderr) = output.get::<(Vec<String>, Vec<String>)>().unwrap();
assert_eq!("testing 123", stdout[0]);
assert_eq!(1, code.unwrap());
return assert!(true);
}
}
_ => {}
}
panic!("Should not be here");
}

0 comments on commit 62a6d11

Please sign in to comment.