Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ErrWithExitCode output #68

Merged
merged 6 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/engine/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
///
/// 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.

Check failure on line 28 in src/engine/dag.rs

View workflow job for this annotation

GitHub Actions / Clippy

doc list item missing indentation
/// - 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

Check failure on line 33 in src/engine/dag.rs

View workflow job for this annotation

GitHub Actions / Clippy

doc list item missing indentation
/// execution of the subsequent task.

Check failure on line 34 in src/engine/dag.rs

View workflow job for this annotation

GitHub Actions / Clippy

doc list item missing indentation
/// - 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.

Check failure on line 36 in src/engine/dag.rs

View workflow job for this annotation

GitHub Actions / Clippy

doc list item missing indentation
///
/// # Example
/// ```rust
Expand Down Expand Up @@ -370,7 +370,7 @@
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
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");
}
Loading