Search in sources :

Example 1 with SCHEDULED

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));
    }
}
Also used : REMOVE_USED_OR_EXPIRED_RESERVED_VALUES(org.hisp.dhis.scheduling.JobType.REMOVE_USED_OR_EXPIRED_RESERVED_VALUES) SchedulingManager(org.hisp.dhis.scheduling.SchedulingManager) JobStatus(org.hisp.dhis.scheduling.JobStatus) AbstractStartupRoutine(org.hisp.dhis.system.startup.AbstractStartupRoutine) Date(java.util.Date) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FILE_RESOURCE_CLEANUP(org.hisp.dhis.scheduling.JobType.FILE_RESOURCE_CLEANUP) MessageService(org.hisp.dhis.message.MessageService) FAILED(org.hisp.dhis.scheduling.JobStatus.FAILED) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) SCHEDULED(org.hisp.dhis.scheduling.JobStatus.SCHEDULED) JobConfigurationService(org.hisp.dhis.scheduling.JobConfigurationService) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) JobType(org.hisp.dhis.scheduling.JobType) Optional(java.util.Optional) SettingKey(org.hisp.dhis.setting.SettingKey) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) ArrayList(java.util.ArrayList) Date(java.util.Date) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Optional (java.util.Optional)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Consumer (java.util.function.Consumer)1 Slf4j (lombok.extern.slf4j.Slf4j)1 MessageService (org.hisp.dhis.message.MessageService)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 JobConfigurationService (org.hisp.dhis.scheduling.JobConfigurationService)1 JobStatus (org.hisp.dhis.scheduling.JobStatus)1 FAILED (org.hisp.dhis.scheduling.JobStatus.FAILED)1 SCHEDULED (org.hisp.dhis.scheduling.JobStatus.SCHEDULED)1 JobType (org.hisp.dhis.scheduling.JobType)1 FILE_RESOURCE_CLEANUP (org.hisp.dhis.scheduling.JobType.FILE_RESOURCE_CLEANUP)1 REMOVE_USED_OR_EXPIRED_RESERVED_VALUES (org.hisp.dhis.scheduling.JobType.REMOVE_USED_OR_EXPIRED_RESERVED_VALUES)1 SchedulingManager (org.hisp.dhis.scheduling.SchedulingManager)1 SettingKey (org.hisp.dhis.setting.SettingKey)1