You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2023/03/23 12:29:57 UTC

[dolphinscheduler] 02/03: feat: Python add online_schedule for workflow control schedule state (#13551)

This is an automated email from the ASF dual-hosted git repository.

zhongjiajie pushed a commit to branch 3.1.5-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit 9d2140a651fb0d363a5b7e10b8f171d1981500c4
Author: Jay Chung <zh...@gmail.com>
AuthorDate: Tue Mar 7 11:35:01 2023 +0800

    feat: Python add online_schedule for workflow control schedule state (#13551)
    
    related: apache/dolphinscheduler-sdk-python#73
---
 .../dolphinscheduler/api/python/PythonGateway.java       | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
index b03ddecf30..e08b675647 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
@@ -215,6 +215,7 @@ public class PythonGateway {
      * @param globalParams global params
      * @param schedule schedule for workflow, will not set schedule if null,
      * and if would always fresh exists schedule if not null
+     * @param onlineSchedule Whether set the workflow's schedule to online state
      * @param warningType warning type
      * @param warningGroupId warning group id
      * @param timeout timeout for workflow working, if running time longer than timeout,
@@ -231,6 +232,7 @@ public class PythonGateway {
                                        String description,
                                        String globalParams,
                                        String schedule,
+                                       boolean onlineSchedule,
                                        String warningType,
                                        int warningGroupId,
                                        int timeout,
@@ -272,7 +274,9 @@ public class PythonGateway {
 
         // Fresh workflow schedule
         if (schedule != null) {
-            createOrUpdateSchedule(user, projectCode, processDefinitionCode, schedule, workerGroup, warningType, warningGroupId);
+            createOrUpdateSchedule(user, projectCode, processDefinitionCode, schedule, onlineSchedule, workerGroup,
+                    warningType,
+                    warningGroupId);
         }
         processDefinitionService.releaseProcessDefinition(user, projectCode, processDefinitionCode, ReleaseState.getEnum(releaseState));
         return processDefinitionCode;
@@ -312,6 +316,7 @@ public class PythonGateway {
      * @param projectCode project which workflow belongs to
      * @param workflowCode workflow code
      * @param schedule schedule expression
+     * @param onlineSchedule Whether set the workflow's schedule to online state
      * @param workerGroup work group
      * @param warningType warning type
      * @param warningGroupId warning group id
@@ -320,6 +325,7 @@ public class PythonGateway {
                                         long projectCode,
                                         long workflowCode,
                                         String schedule,
+                                        boolean onlineSchedule,
                                         String workerGroup,
                                         String warningType,
                                         int warningGroupId) {
@@ -340,9 +346,11 @@ public class PythonGateway {
             schedulerService.updateSchedule(user, projectCode, scheduleId, schedule, WarningType.valueOf(warningType),
                     warningGroupId, DEFAULT_FAILURE_STRATEGY, DEFAULT_PRIORITY, workerGroup, DEFAULT_ENVIRONMENT_CODE);
         }
-        // Always set workflow online to set schedule online
-        processDefinitionService.releaseProcessDefinition(user, projectCode, workflowCode, ReleaseState.ONLINE);
-        schedulerService.setScheduleState(user, projectCode, scheduleId, ReleaseState.ONLINE);
+        if (onlineSchedule) {
+            // set workflow online to make sure we can set schedule online
+            processDefinitionService.releaseProcessDefinition(user, projectCode, workflowCode, ReleaseState.ONLINE);
+            schedulerService.setScheduleState(user, projectCode, scheduleId, ReleaseState.ONLINE);
+        }
     }
 
     public void execWorkflowInstance(String userName,