You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/06/27 01:49:13 UTC

[GitHub] [dolphinscheduler] caishunfeng commented on a diff in pull request #10613: [fix-10608] [worker] move setting of TaskExecutionContext to finally block

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


##########
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.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org