diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/BaseLoopTaskExecutor.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/BaseLoopTaskExecutor.java index 15dd25e236..3c4857f2d0 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/BaseLoopTaskExecutor.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/BaseLoopTaskExecutor.java @@ -54,10 +54,21 @@ public abstract class BaseLoopTaskExecutor extends AbstractTaskExecutor { // loop the task status until the task is finished or task has been canceled. // we use retry utils here to avoid the task status query failure due to network failure. // the default retry policy is 3 times, and the interval is 1 second. - while (!cancel - && !RetryUtils.retryFunction(() -> queryTaskInstanceStatus(loopTaskInstanceInfo).isFinished())) { + LoopTaskInstanceStatus loopTaskInstanceStatus = null; + while (!cancel) { + loopTaskInstanceStatus = RetryUtils.retryFunction(() -> queryTaskInstanceStatus(loopTaskInstanceInfo)); + if (loopTaskInstanceStatus.isFinished()) { + break; + } Thread.sleep(loopInterval); } + if (loopTaskInstanceStatus != null && loopTaskInstanceStatus.isSuccess()) { + setExitStatusCode(TaskConstants.EXIT_CODE_SUCCESS); + logger.info("The task instance: {} execute successfully.", appIds); + } else { + setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE); + logger.info("The task instance: {} is execute failure.", appIds); + } } catch (InterruptedException e) { setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE); logger.error("The current loop thread has been interrupted", e); diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/LoopTaskInstanceStatus.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/LoopTaskInstanceStatus.java index 75067023cd..6d66dfd1cb 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/LoopTaskInstanceStatus.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/LoopTaskInstanceStatus.java @@ -23,7 +23,15 @@ package org.apache.dolphinscheduler.plugin.task.api.loop; public interface LoopTaskInstanceStatus { /** * Judge if the task instance is finished. + * * @return true if the task instance is finished, false otherwise. */ boolean isFinished(); + + /** + * Judge if the task instance is success. + * + * @return true if the task instance is success, false otherwise. + */ + boolean isSuccess(); } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/HttpLoopTaskInstanceStatus.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/HttpLoopTaskInstanceStatus.java index 1c0c75b473..33381aa2d0 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/HttpLoopTaskInstanceStatus.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/loop/template/http/HttpLoopTaskInstanceStatus.java @@ -28,4 +28,8 @@ public class HttpLoopTaskInstanceStatus implements LoopTaskInstanceStatus { private final boolean finished; + @Override + public boolean isSuccess() { + return true; + } }