Skip to content

Commit ef56d03

Browse files
authored
[Fix-17820][Master] Fix task timeout alerts failed (#17818)
1 parent fd4154e commit ef56d03

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ private void saveTaskTimeoutAlert(Alert alert, String content, int alertGroupId)
244244
public void sendTaskTimeoutAlert(WorkflowInstance workflowInstance,
245245
TaskInstance taskInstance,
246246
ProjectUser projectUser) {
247+
if (projectUser == null) {
248+
throw new IllegalArgumentException("projectUser must not be null");
249+
}
250+
if (workflowInstance.getWarningGroupId() == null) {
251+
throw new IllegalArgumentException("warningGroupId of the workflow instance must not be null");
252+
}
253+
247254
Alert alert = new Alert();
248255
List<WorkflowAlertContent> workflowAlertContentList = new ArrayList<>(1);
249256
WorkflowAlertContent workflowAlertContent = WorkflowAlertContent.builder()

dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/ProjectDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.dolphinscheduler.dao.repository;
1919

2020
import org.apache.dolphinscheduler.dao.entity.Project;
21+
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
2122

2223
import java.util.Collection;
2324
import java.util.List;
@@ -28,4 +29,5 @@ public interface ProjectDao extends IDao<Project> {
2829

2930
Project queryByCode(Long projectCode);
3031

32+
ProjectUser queryProjectWithUserByWorkflowInstanceId(int workflowInstanceId);
3133
}

dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/ProjectDaoImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.dolphinscheduler.dao.repository.impl;
1919

2020
import org.apache.dolphinscheduler.dao.entity.Project;
21+
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
2122
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
2223
import org.apache.dolphinscheduler.dao.repository.BaseDao;
2324
import org.apache.dolphinscheduler.dao.repository.ProjectDao;
@@ -45,4 +46,9 @@ public List<Project> queryByCodes(Collection<Long> projectCodes) {
4546
public Project queryByCode(Long projectCode) {
4647
return mybatisMapper.queryByCode(projectCode);
4748
}
49+
50+
@Override
51+
public ProjectUser queryProjectWithUserByWorkflowInstanceId(int workflowInstanceId) {
52+
return mybatisMapper.queryProjectWithUserByWorkflowInstanceId(workflowInstanceId);
53+
}
4854
}

dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/task/lifecycle/handler/TaskTimeoutLifecycleEventHandler.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ public void handle(final ITaskStateAction taskStateAction,
6262
log.info("The task {} TimeoutStrategy is null.", taskName);
6363
return;
6464
}
65+
66+
final WorkflowInstance workflowInstance = workflowExecutionRunnable.getWorkflowInstance();
67+
final boolean shouldSendAlert = workflowInstance.getWarningGroupId() != null;
68+
6569
switch (timeoutNotifyStrategy) {
6670
case WARN:
6771
log.info("The task {} TimeoutStrategy is WARN, try to send a timeout alert.", taskName);
68-
doTaskTimeoutAlert(taskExecutionRunnable);
72+
if (shouldSendAlert) {
73+
doTaskTimeoutAlert(taskExecutionRunnable);
74+
} else {
75+
log.info("Skipped sending timeout alert for task {} because warningGroupId is null.", taskName);
76+
}
6977
break;
7078
case FAILED:
7179
log.info("The task {} TimeoutStrategy is FAILED, try to publish a kill event.", taskName);
@@ -76,7 +84,11 @@ public void handle(final ITaskStateAction taskStateAction,
7684
"The task {} TimeoutStrategy is WARNFAILED, try to publish a kill event and send a timeout alert.",
7785
taskName);
7886
doTaskTimeoutKill(taskExecutionRunnable);
79-
doTaskTimeoutAlert(taskExecutionRunnable);
87+
if (shouldSendAlert) {
88+
doTaskTimeoutAlert(taskExecutionRunnable);
89+
} else {
90+
log.info("Skipped sending timeout alert for task {} because warningGroupId is null.", taskName);
91+
}
8092
default:
8193
log.warn("The task {} TimeoutStrategy is invalided.", taskName);
8294
break;
@@ -90,8 +102,7 @@ private void doTaskTimeoutKill(final ITaskExecutionRunnable taskExecutionRunnabl
90102
private void doTaskTimeoutAlert(final ITaskExecutionRunnable taskExecutionRunnable) {
91103
final WorkflowInstance workflowInstance = taskExecutionRunnable.getWorkflowInstance();
92104
final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
93-
// todo: inject the projectUser
94-
workflowAlertManager.sendTaskTimeoutAlert(workflowInstance, taskInstance, null);
105+
workflowAlertManager.sendTaskTimeoutAlert(workflowInstance, taskInstance);
95106
}
96107

97108
@Override

dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/WorkflowAlertManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ public boolean isNeedToSendWarning(WorkflowInstance workflowInstance) {
260260
}
261261

262262
public void sendTaskTimeoutAlert(WorkflowInstance workflowInstance,
263-
TaskInstance taskInstance,
264-
ProjectUser projectUser) {
263+
TaskInstance taskInstance) {
264+
ProjectUser projectUser = projectDao.queryProjectWithUserByWorkflowInstanceId(workflowInstance.getId());
265265
alertDao.sendTaskTimeoutAlert(workflowInstance, taskInstance, projectUser);
266266
}
267267
}

0 commit comments

Comments
 (0)