Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -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 @@ -31,6 +31,7 @@
import org.apache.dolphinscheduler.dao.entity.WorkflowAlertContent;
import org.apache.dolphinscheduler.dao.entity.WorkflowDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.WorkflowInstance;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.repository.ProjectDao;
import org.apache.dolphinscheduler.dao.repository.UserDao;
import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionLogDao;
Expand Down Expand Up @@ -60,6 +61,9 @@ public class WorkflowAlertManager {
@Autowired
private ProjectDao projectDao;

@Autowired
private ProjectMapper projectMapper;

/**
* convert command type to human-readable name
*
Expand Down Expand Up @@ -260,8 +264,8 @@ public boolean isNeedToSendWarning(WorkflowInstance workflowInstance) {
}

public void sendTaskTimeoutAlert(WorkflowInstance workflowInstance,
TaskInstance taskInstance,
ProjectUser projectUser) {
TaskInstance taskInstance) {
ProjectUser projectUser = projectMapper.queryProjectWithUserByWorkflowInstanceId(workflowInstance.getId());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use ProjectDao instead of directly use ProjectMapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use ProjectDao instead of directly use ProjectMapper.

ok, it's better

alertDao.sendTaskTimeoutAlert(workflowInstance, taskInstance, projectUser);
}
}