Skip to content

Commit

Permalink
restart
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinKirs committed Dec 13, 2024
1 parent 409c21d commit d1e2998
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,26 @@ public void onReplayCreate() throws JobException {
public void onReplayEnd(AbstractJob<?, C> replayJob) throws JobException {
log.info(new LogBuilder(LogKey.SCHEDULER_JOB, getJobId()).add("msg", "replay delete scheduler job").build());
}

private void updateTaskStatusAfterRestart() {

public void updateTaskStatusAfterRestart() {
List<T> tasks = queryAllTasks();
if (CollectionUtils.isEmpty(tasks)) {
return;
}
List<T> runningTasks = tasks.stream().filter(task -> task.getStatus().equals(TaskStatus.RUNNING) || task.getStatus().equals(TaskStatus.PENDING))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(runningTasks)) {
return;
}

runningTasks.forEach(task -> {
if (task.getStatus().equals(TaskStatus.RUNNING)) {
task.setStatus(TaskStatus.PENDING);
try {
task.onFail("task failed because of restart");
} catch (JobException e) {
log.warn("task failed because of restart, job id is {}, task id is {}",
jobId, task.getTaskId(), e);
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ private void writeUnlock() {

public void start() {
jobScheduler = new JobScheduler<T, C>(jobMap);
clearTaskStatusWhenFeRestart();
jobScheduler.start();
}

private void clearTaskStatusWhenFeRestart() {
public void clearTaskStatusWhenFeRestart() {
List<T> runningJobs = jobMap.values().stream()
.filter(job -> job.getJobStatus().equals(JobStatus.RUNNING)).collect(Collectors.toList());
for (T job : runningJobs) {

job.updateTaskStatusAfterRestart();
}
}

Expand Down

0 comments on commit d1e2998

Please sign in to comment.