-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Alert on unscheduled workflows
- Loading branch information
1 parent
802a59a
commit e7b6788
Showing
3 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...-platform-monitor/src/main/java/com/flink/platform/monitor/UnscheduledJobFlowChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.flink.platform.monitor; | ||
|
||
import com.flink.platform.alert.AlertSendingService; | ||
import com.flink.platform.dao.entity.Worker; | ||
import com.flink.platform.dao.service.JobFlowService; | ||
import com.flink.platform.dao.service.WorkerService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static com.flink.platform.common.enums.WorkerStatus.LEADER; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor(onConstructor_ = @Autowired) | ||
public class UnscheduledJobFlowChecker { | ||
|
||
private static final String ALERT_TEMPLATE = | ||
"\\nWorkflow's crontab is set but not scheduled: \\nName: %s, Status: %s."; | ||
|
||
private final WorkerService workerService; | ||
|
||
private final JobFlowService jobFlowService; | ||
|
||
private final AlertSendingService alertSendingService; | ||
|
||
@Scheduled(initialDelay = 2 * 60 * 1000, fixedDelay = 60 * 60 * 1000) | ||
public void checkUnscheduledWorkflow() { | ||
Worker worker = workerService.getCurrentWorker(); | ||
if (worker == null || !LEADER.equals(worker.getRole())) { | ||
log.info("Current worker is not leader, skip checkUnscheduledWorkflow."); | ||
return; | ||
} | ||
|
||
jobFlowService.getUnscheduledJobFlows().forEach(jobFlow -> { | ||
String content = String.format( | ||
ALERT_TEMPLATE, jobFlow.getName(), jobFlow.getStatus().name()); | ||
alertSendingService.sendErrAlerts(jobFlow, content); | ||
}); | ||
} | ||
} |