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

SbloodyS pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 5d9d23e982 [Fix-18731][API] Offline schedules when switching workflow 
versions (#18732)
5d9d23e982 is described below

commit 5d9d23e98239983e40c8f219e84200fda31c092c
Author: Kerwin <[email protected]>
AuthorDate: Fri Oct 23 17:47:29 2026 +0800

    [Fix-18731][API] Offline schedules when switching workflow versions (#18732)
---
 .../impl/WorkflowDefinitionServiceImpl.java        |  1 +
 .../api/service/WorkflowDefinitionServiceTest.java | 26 ++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
index 3bfc272e6f..73e09aea63 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
@@ -1716,6 +1716,7 @@ public class WorkflowDefinitionServiceImpl extends 
BaseServiceImpl implements Wo
                     projectCode, code, version);
             throw new 
ServiceException(Status.SWITCH_WORKFLOW_DEFINITION_VERSION_ERROR);
         }
+        schedulerService.offlineSchedulerByWorkflowCode(code);
 
         saveWorkflowLineage(workflowDefinitionLog.getProjectCode(), 
workflowDefinitionLog.getCode(),
                 workflowDefinitionLog.getVersion(), taskDefinitionLogList);
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowDefinitionServiceTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowDefinitionServiceTest.java
index c0f30985f4..3824116092 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowDefinitionServiceTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowDefinitionServiceTest.java
@@ -1159,6 +1159,32 @@ public class WorkflowDefinitionServiceTest extends 
BaseServiceTestTool {
                 .switchVersion(any(WorkflowDefinition.class), 
any(WorkflowDefinitionLog.class));
     }
 
+    @Test
+    public void testSwitchWorkflowDefinitionVersionShouldOfflineSchedule() {
+        WorkflowDefinition workflowDefinition = getWorkflowDefinition();
+        WorkflowDefinitionLog workflowDefinitionLog = new 
WorkflowDefinitionLog();
+        workflowDefinitionLog.setCode(processDefinitionCode);
+        workflowDefinitionLog.setProjectCode(projectCode);
+        workflowDefinitionLog.setVersion(1);
+        WorkflowTaskRelation workflowTaskRelation =
+                getWorkflowTaskRelation(1, 1, projectCode, 
processDefinitionCode, 0, 0, 123456789L, 1);
+        TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog();
+        taskDefinitionLog.setTaskType("SHELL");
+
+        
when(workflowDefinitionDao.queryByCode(processDefinitionCode)).thenReturn(Optional.of(workflowDefinition));
+        
when(workflowDefinitionLogMapper.queryByDefinitionCodeAndVersion(processDefinitionCode,
 1))
+                .thenReturn(workflowDefinitionLog);
+        
when(workflowTaskRelationDao.queryWorkflowTaskRelationsByWorkflowDefinitionCode(processDefinitionCode,
 1))
+                .thenReturn(Collections.singletonList(workflowTaskRelation));
+        when(taskDefinitionLogMapper.queryByTaskDefinitions(anyList()))
+                .thenReturn(Collections.singletonList(taskDefinitionLog));
+        when(processService.switchVersion(workflowDefinition, 
workflowDefinitionLog)).thenReturn(1);
+
+        workflowDefinitionService.switchWorkflowDefinitionVersion(user, 
projectCode, processDefinitionCode, 1);
+
+        
verify(schedulerService).offlineSchedulerByWorkflowCode(processDefinitionCode);
+    }
+
     @Test
     public void 
testOnlineWorkflowDefinitionShouldRejectUnauthorizedDatasource() {
         WorkflowDefinition workflowDefinition = getWorkflowDefinition();

Reply via email to