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/25 09:11:25 UTC

[GitHub] [dolphinscheduler] guoshupei opened a new pull request, #10613: [fix-10608] [worker] move setting of TaskExecutionContext to finally block

guoshupei opened a new pull request, #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613

   
   
   <!--Thanks very much for contributing to Apache DolphinScheduler. Please review https://dolphinscheduler.apache.org/en-us/community/development/pull-request.html before opening a pull request.-->
   
   
   ## Purpose of the pull request
   #10608 
   <!--(For example: This pull request adds checkstyle plugin).-->
   
   ## Brief change log
   - move setting to finally
   - add log
   
   <!--*(for example:)*
     - *Add maven-checkstyle-plugin to root pom.xml*
   -->
   ## Verify this pull request
   
   <!--*(Please pick either of the following options)*-->
   
   This pull request is code cleanup without any test coverage.
   
   *(or)*
   
   This pull request is already covered by existing tests, such as *(please describe tests)*.
   
   (or)
   
   This change added tests and can be verified as follows:
   
   <!--*(example:)*
     - *Added dolphinscheduler-dao tests for end-to-end.*
     - *Added CronUtilsTest to verify the change.*
     - *Manually verified the change by testing locally.* -->
   


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


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

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r907951557


##########
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:
   You can define a ExecutionStatus and set the value at catch, just like errorFlag, then you don't need to parse the status from task.
   ```java
   ExecutionStatus executionStatus;
   try{
   executionStatus = ExecutionStatus.of(this.task.getExitStatus().getCode());
   }catch(Exception) {
   executionStatus = ExecutionStatus.FAILURE;
   }finally{
   taskExecutionContext.setCurrentExecutionStatus(executionStatus);
   }
   ```



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


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

Posted by GitBox <gi...@apache.org>.
guoshupei commented on PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#issuecomment-1166243208

   > And please revert the change of setVarPool.
   > 
   > ```
   > taskExecutionContext.setVarPool(JSONUtils.toJsonString(this.task.getParameters().getVarPool()));
   > ```
   
   good idea.


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


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

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r907426438


##########
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:
   It seems you didn't handle the task may be null in finally.



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


[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10613: [fix-10608] [worker] move setting of TaskExecutionContext to finally block

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#issuecomment-1166241595

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10613)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=CODE_SMELL)
   
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/0-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10613&metric=new_coverage&view=list) [0.0% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10613&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10613&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10613&metric=new_duplicated_lines_density&view=list)
   
   


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


[GitHub] [dolphinscheduler] caishunfeng closed pull request #10613: [fix-10608] [worker] move setting of TaskExecutionContext to finally block

Posted by GitBox <gi...@apache.org>.
caishunfeng closed pull request #10613: [fix-10608] [worker] move setting of TaskExecutionContext to finally block
URL: https://github.com/apache/dolphinscheduler/pull/10613


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


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

Posted by GitBox <gi...@apache.org>.
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 move 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: commits-unsubscribe@dolphinscheduler.apache.org

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


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

Posted by GitBox <gi...@apache.org>.
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


[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10613: [fix-10608] [worker] move setting of TaskExecutionContext to finally block

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#issuecomment-1166247429

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10613)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10613&resolved=false&types=CODE_SMELL)
   
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/0-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10613&metric=new_coverage&view=list) [0.0% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10613&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10613&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10613&metric=new_duplicated_lines_density&view=list)
   
   


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


[GitHub] [dolphinscheduler] codecov-commenter commented on pull request #10613: [fix-10608] [worker] move setting of TaskExecutionContext to finally block

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#issuecomment-1166240036

   # [Codecov](https://codecov.io/gh/apache/dolphinscheduler/pull/10613?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#10613](https://codecov.io/gh/apache/dolphinscheduler/pull/10613?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9662ef5) into [dev](https://codecov.io/gh/apache/dolphinscheduler/commit/16144a8858ab538be797f93abaaef8f291878eff?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (16144a8) will **not change** coverage.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@            Coverage Diff            @@
   ##                dev   #10613   +/-   ##
   =========================================
     Coverage     40.93%   40.93%           
     Complexity     4875     4875           
   =========================================
     Files           895      895           
     Lines         36212    36212           
     Branches       3987     3989    +2     
   =========================================
     Hits          14824    14824           
     Misses        19922    19922           
     Partials       1466     1466           
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/dolphinscheduler/pull/10613?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...r/server/worker/processor/TaskCallbackService.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10613/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZG9scGhpbnNjaGVkdWxlci13b3JrZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvc2VydmVyL3dvcmtlci9wcm9jZXNzb3IvVGFza0NhbGxiYWNrU2VydmljZS5qYXZh) | `2.12% <0.00%> (-0.03%)` | :arrow_down: |
   | [...eduler/server/worker/runner/TaskExecuteThread.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10613/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZG9scGhpbnNjaGVkdWxlci13b3JrZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvc2VydmVyL3dvcmtlci9ydW5uZXIvVGFza0V4ZWN1dGVUaHJlYWQuamF2YQ==) | `15.97% <0.00%> (+0.11%)` | :arrow_up: |
   | [...dolphinscheduler/remote/future/ResponseFuture.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10613/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZG9scGhpbnNjaGVkdWxlci1yZW1vdGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvcmVtb3RlL2Z1dHVyZS9SZXNwb25zZUZ1dHVyZS5qYXZh) | `81.96% <0.00%> (-1.64%)` | :arrow_down: |
   | [...er/master/dispatch/host/assign/RandomSelector.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10613/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZG9scGhpbnNjaGVkdWxlci1tYXN0ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvc2VydmVyL21hc3Rlci9kaXNwYXRjaC9ob3N0L2Fzc2lnbi9SYW5kb21TZWxlY3Rvci5qYXZh) | `83.33% <0.00%> (+5.55%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/dolphinscheduler/pull/10613?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/dolphinscheduler/pull/10613?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [16144a8...9662ef5](https://codecov.io/gh/apache/dolphinscheduler/pull/10613?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


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


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

Posted by GitBox <gi...@apache.org>.
guoshupei commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r908367923


##########
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:
   the task is also used in getProcessId() and getAppIds() , 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


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

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

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


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

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r907428341


##########
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:
   You can use executionStatus to replace the errorFlag, then you don't need to deal with the task in finally.



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


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

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r906661375


##########
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java:
##########
@@ -191,21 +192,20 @@ public void run() {
             if (this.task.getNeedAlert()) {
                 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 {
+            taskExecutionContext.setCurrentExecutionStatus(errorFlag ? ExecutionStatus.FAILURE : ExecutionStatus.of(this.task.getExitStatus().getCode()));
             taskExecutionContext.setEndTime(DateUtils.getCurrentDate());
             taskExecutionContext.setProcessId(this.task.getProcessId());
             taskExecutionContext.setAppIds(this.task.getAppIds());
-        } finally {
+            if (!errorFlag) {
+                taskExecutionContext.setVarPool(JSONUtils.toJsonString(this.task.getParameters().getVarPool()));
+            }
+

Review Comment:
   ```suggestion
           } 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());
                       taskExecutionContext.setAppIds(this.task.getAppIds());
   ```



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


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

Posted by GitBox <gi...@apache.org>.
guoshupei commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r907942893


##########
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:
   How do I determine whether a task is null through executionStatus?There may be the same value` ExecutionStatus.FAILURE` in try block and catch block and task may also be null.  I think if task throw NPE, it need to add NPE check in both catch block and finally block . so I think add check in finally is better.



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


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

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#discussion_r907951557


##########
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:
   You can define a ExecutionStatus and set the value at catch, then you don't need to parse the status from task.
   ```java
   ExecutionStatus executionStatus;
   try{
   executionStatus = ExecutionStatus.of(this.task.getExitStatus().getCode());
   }catch(Exception) {
   executionStatus = ExecutionStatus.FAILURE;
   }finally{
   taskExecutionContext.setCurrentExecutionStatus(executionStatus);
   }
   ```



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


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

Posted by GitBox <gi...@apache.org>.
caishunfeng commented on PR #10613:
URL: https://github.com/apache/dolphinscheduler/pull/10613#issuecomment-1248837782

   No update for months, the lastest code had changed, so I will close this pr.


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