Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ private void saveTaskTimeoutAlert(Alert alert, String content, int alertGroupId)
public void sendTaskTimeoutAlert(WorkflowInstance workflowInstance,
TaskInstance taskInstance,
ProjectUser projectUser) {
if (projectUser == null) {
throw new IllegalArgumentException("projectUser must not be null");
}
if (workflowInstance.getWarningGroupId() == null) {
throw new IllegalArgumentException("warningGroupId of the workflow instance must not be null");
}

Alert alert = new Alert();
List<WorkflowAlertContent> workflowAlertContentList = new ArrayList<>(1);
WorkflowAlertContent workflowAlertContent = WorkflowAlertContent.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.dao.repository;

import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.ProjectUser;

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

Project queryByCode(Long projectCode);

ProjectUser queryProjectWithUserByWorkflowInstanceId(int workflowInstanceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.dao.repository.impl;

import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.repository.BaseDao;
import org.apache.dolphinscheduler.dao.repository.ProjectDao;
Expand Down Expand Up @@ -45,4 +46,9 @@ public List<Project> queryByCodes(Collection<Long> projectCodes) {
public Project queryByCode(Long projectCode) {
return mybatisMapper.queryByCode(projectCode);
}

@Override
public ProjectUser queryProjectWithUserByWorkflowInstanceId(int workflowInstanceId) {
return mybatisMapper.queryProjectWithUserByWorkflowInstanceId(workflowInstanceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ public void handle(final ITaskStateAction taskStateAction,
log.info("The task {} TimeoutStrategy is null.", taskName);
return;
}

final WorkflowInstance workflowInstance = workflowExecutionRunnable.getWorkflowInstance();
final boolean shouldSendAlert = workflowInstance.getWarningGroupId() != null;

switch (timeoutNotifyStrategy) {
case WARN:
log.info("The task {} TimeoutStrategy is WARN, try to send a timeout alert.", taskName);
doTaskTimeoutAlert(taskExecutionRunnable);
if (shouldSendAlert) {
doTaskTimeoutAlert(taskExecutionRunnable);
} else {
log.info("Skipped sending timeout alert for task {} because warningGroupId is null.", taskName);
}
break;
case FAILED:
log.info("The task {} TimeoutStrategy is FAILED, try to publish a kill event.", taskName);
Expand All @@ -76,7 +84,11 @@ public void handle(final ITaskStateAction taskStateAction,
"The task {} TimeoutStrategy is WARNFAILED, try to publish a kill event and send a timeout alert.",
taskName);
doTaskTimeoutKill(taskExecutionRunnable);
doTaskTimeoutAlert(taskExecutionRunnable);
if (shouldSendAlert) {
doTaskTimeoutAlert(taskExecutionRunnable);
} else {
log.info("Skipped sending timeout alert for task {} because warningGroupId is null.", taskName);
}
default:
log.warn("The task {} TimeoutStrategy is invalided.", taskName);
break;
Expand All @@ -90,8 +102,7 @@ private void doTaskTimeoutKill(final ITaskExecutionRunnable taskExecutionRunnabl
private void doTaskTimeoutAlert(final ITaskExecutionRunnable taskExecutionRunnable) {
final WorkflowInstance workflowInstance = taskExecutionRunnable.getWorkflowInstance();
final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
// todo: inject the projectUser
workflowAlertManager.sendTaskTimeoutAlert(workflowInstance, taskInstance, null);
workflowAlertManager.sendTaskTimeoutAlert(workflowInstance, taskInstance);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ public boolean isNeedToSendWarning(WorkflowInstance workflowInstance) {
}

public void sendTaskTimeoutAlert(WorkflowInstance workflowInstance,
TaskInstance taskInstance,
ProjectUser projectUser) {
TaskInstance taskInstance) {
ProjectUser projectUser = projectDao.queryProjectWithUserByWorkflowInstanceId(workflowInstance.getId());
alertDao.sendTaskTimeoutAlert(workflowInstance, taskInstance, projectUser);
}
}
Loading