diff --git a/src/engine/dag.rs b/src/engine/dag.rs index 5cedb84..471887e 100644 --- a/src/engine/dag.rs +++ b/src/engine/dag.rs @@ -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 @@ -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); diff --git a/src/task/cmd.rs b/src/task/cmd.rs index a00d175..69942e3 100644 --- a/src/task/cmd.rs +++ b/src/task/cmd.rs @@ -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) => { diff --git a/src/task/state.rs b/src/task/state.rs index 5fbe0ee..300a125 100644 --- a/src/task/state.rs +++ b/src/task/state.rs @@ -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::()?.to_string()) - } else { - None - } + Self::ErrWithExitCode(code, _) => { + let error_code = code.map_or("".to_string(), |v| v.to_string()); + Some(format!("code: {error_code}")) } } } diff --git a/src/utils/parser.rs b/src/utils/parser.rs index 9c9b303..b706fde 100644 --- a/src/utils/parser.rs +++ b/src/utils/parser.rs @@ -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. diff --git a/tests/dag_job_test.rs b/tests/dag_job_test.rs index 3a8f65d..2f57f6b 100644 --- a/tests/dag_job_test.rs +++ b/tests/dag_job_test.rs @@ -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, Vec)>().unwrap(); + assert_eq!("testing 123", stdout[0]); + assert_eq!(1, code.unwrap()); + return assert!(true); + } + } + _ => {} + } + panic!("Should not be here"); +}