guoshupei commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r907237536


##########
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java:
##########
@@ -192,20 +193,23 @@ public void run() {
                 sendAlert(this.task.getTaskAlertInfo(), 
this.task.getExitStatus().getCode());
             }
 
-            
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.of(this.task.getExitStatus().getCode()));
-            taskExecutionContext.setEndTime(DateUtils.getCurrentDate());
-            taskExecutionContext.setProcessId(this.task.getProcessId());
-            taskExecutionContext.setAppIds(this.task.getAppIds());
             
taskExecutionContext.setVarPool(JSONUtils.toJsonString(this.task.getParameters().getVarPool()));
-            logger.info("task instance id : {},task final status : {}", 
taskExecutionContext.getTaskInstanceId(), this.task.getExitStatus());
+
+            logger.info("task instance id : {}, task final status : {}", 
taskExecutionContext.getTaskInstanceId(), this.task.getExitStatus());
         } catch (Throwable e) {
-            logger.error("task scheduler failure", e);
+            logger.error("task instance id : {}, scheduler failure", 
taskExecutionContext.getTaskInstanceId(), e);
+            errorFlag = true;
             kill();
-            
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.FAILURE);
+        } finally {
+            if (errorFlag) {
+                
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.FAILURE);
+            } else {
+                
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.of(this.task.getExitStatus().getCode()));
+            }
             taskExecutionContext.setEndTime(DateUtils.getCurrentDate());
             taskExecutionContext.setProcessId(this.task.getProcessId());

Review Comment:
   > If in finally, the task maybe null, so it need to add NPE check.
   
   yes, I check again. you are right. if add NPE check, I think setting in try 
block and catch block is better. it readability is better. WDYT?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to