use of org.hisp.dhis.scheduling.JobStatus.SCHEDULED in project dhis2-core by dhis2.
the class SchedulerStart method execute.
@Override
public void execute() throws Exception {
Date now = new Date();
List<String> unexecutedJobs = new ArrayList<>();
List<JobConfiguration> jobConfigurations = jobConfigurationService.getAllJobConfigurations();
addDefaultJobs(jobConfigurations);
jobConfigurations.forEach((jobConfig -> {
if (jobConfig.isEnabled()) {
Date oldExecutionTime = jobConfig.getNextExecutionTime();
jobConfig.setNextExecutionTime(null);
jobConfig.setJobStatus(SCHEDULED);
jobConfigurationService.updateJobConfiguration(jobConfig);
if (jobConfig.getLastExecutedStatus() == FAILED || (oldExecutionTime != null && oldExecutionTime.compareTo(now) < 0)) {
unexecutedJobs.add("\nJob [" + jobConfig.getUid() + ", " + jobConfig.getName() + "] has status failed or was scheduled in server downtime. Actual execution time was supposed to be: " + oldExecutionTime);
}
schedulingManager.schedule(jobConfig);
}
}));
if (!unexecutedJobs.isEmpty()) {
StringBuilder jobs = new StringBuilder();
for (String unexecutedJob : unexecutedJobs) {
jobs.append(unexecutedJob).append("\n");
}
messageService.sendSystemErrorNotification("Scheduler startup", new Exception("Scheduler started with one or more unexecuted jobs:\n" + jobs));
}
}
Aggregations