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 all 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
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");
}
Loading