Search in sources :

Example 1 with SchedulerService

use of org.openmrs.scheduler.SchedulerService in project openmrs-module-pihcore by PIH.

the class CloseStaleVisitsSetup method setupCloseStaleVisitsTask.

public static void setupCloseStaleVisitsTask() {
    SchedulerService schedulerService = Context.getSchedulerService();
    TaskDefinition task = schedulerService.getTaskByName(EmrConstants.TASK_CLOSE_STALE_VISITS_NAME);
    if (task == null) {
        task = new TaskDefinition();
        task.setName(EmrConstants.TASK_CLOSE_STALE_VISITS_NAME);
        task.setDescription(EmrConstants.TASK_CLOSE_STALE_VISITS_DESCRIPTION);
        task.setTaskClass(PihCloseStaleVisitsTask.class.getName());
        task.setStartTime(DateUtils.addMinutes(new Date(), 5));
        task.setRepeatInterval(EmrConstants.TASK_CLOSE_STALE_VISITS_REPEAT_INTERVAL);
        task.setStartOnStartup(true);
        try {
            schedulerService.scheduleTask(task);
        } catch (SchedulerException e) {
            throw new RuntimeException("Failed to schedule close stale visits task", e);
        }
    } else {
        // if you modify any of the properties above, you also need to set them here, in order to update existing servers
        boolean changed = GeneralUtils.setPropertyIfDifferent(task, "taskClass", PihCloseStaleVisitsTask.class.getName());
        if (changed) {
            schedulerService.saveTaskDefinition(task);
        }
        if (!task.getStarted()) {
            task.setStarted(true);
            try {
                schedulerService.scheduleTask(task);
            } catch (SchedulerException e) {
                throw new RuntimeException("Failed to schedule close stale visits task", e);
            }
        }
    }
}
Also used : SchedulerService(org.openmrs.scheduler.SchedulerService) TaskDefinition(org.openmrs.scheduler.TaskDefinition) SchedulerException(org.openmrs.scheduler.SchedulerException) PihCloseStaleVisitsTask(org.openmrs.module.pihcore.task.PihCloseStaleVisitsTask) Date(java.util.Date)

Example 2 with SchedulerService

use of org.openmrs.scheduler.SchedulerService in project openmrs-module-pihcore by PIH.

the class RetireProvidersSetup method setupRetireProvidersTask.

public static void setupRetireProvidersTask() {
    SchedulerService schedulerService = Context.getSchedulerService();
    TaskDefinition task = schedulerService.getTaskByName(TASK_RETIRE_PROVIDERS);
    if (task == null) {
        task = new TaskDefinition();
        task.setName(TASK_RETIRE_PROVIDERS);
        task.setDescription(TASK_RETIRE_PROVIDERS);
        task.setTaskClass(UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts.class.getName());
        task.setStartTime(DateUtils.addMinutes(new Date(), 5));
        task.setRepeatInterval(TASK_RETIRE_PROVIDERS_REPEAT_INTERVAL);
        task.setStartOnStartup(true);
        try {
            schedulerService.scheduleTask(task);
        } catch (SchedulerException e) {
            throw new RuntimeException("Failed to schedule retire old providers task", e);
        }
    } else {
        // if you modify any of the properties above, you also need to set them here, in order to update existing servers
        boolean changed = GeneralUtils.setPropertyIfDifferent(task, "taskClass", UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts.class.getName());
        if (changed) {
            schedulerService.saveTaskDefinition(task);
        }
        if (!task.getStarted()) {
            task.setStarted(true);
            try {
                schedulerService.scheduleTask(task);
            } catch (SchedulerException e) {
                throw new RuntimeException("Failed to schedule retire old providers task", e);
            }
        }
    }
}
Also used : SchedulerService(org.openmrs.scheduler.SchedulerService) TaskDefinition(org.openmrs.scheduler.TaskDefinition) SchedulerException(org.openmrs.scheduler.SchedulerException) UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts(org.openmrs.module.pihcore.task.UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts) Date(java.util.Date)

Example 3 with SchedulerService

use of org.openmrs.scheduler.SchedulerService in project openmrs-core by openmrs.

the class WebModuleUtil method stopTasks.

/**
 * Stops all tasks started by given module
 * @param mod
 */
private static void stopTasks(Module mod) {
    SchedulerService schedulerService = Context.getSchedulerService();
    String modulePackageName = mod.getPackageName();
    for (TaskDefinition task : schedulerService.getRegisteredTasks()) {
        String taskClass = task.getTaskClass();
        if (isModulePackageNameInTaskClass(modulePackageName, taskClass)) {
            try {
                schedulerService.shutdownTask(task);
            } catch (SchedulerException e) {
                log.error("Couldn't stop task:" + task + " for module: " + mod);
            }
        }
    }
}
Also used : SchedulerService(org.openmrs.scheduler.SchedulerService) TaskDefinition(org.openmrs.scheduler.TaskDefinition) SchedulerException(org.openmrs.scheduler.SchedulerException)

Example 4 with SchedulerService

use of org.openmrs.scheduler.SchedulerService in project openmrs-module-mirebalais by PIH.

the class ArchivesSetup method setupCloseStalePullRequestsTask.

public static void setupCloseStalePullRequestsTask() {
    SchedulerService schedulerService = Context.getSchedulerService();
    TaskDefinition task = schedulerService.getTaskByName(PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS);
    if (task == null) {
        task = new TaskDefinition();
        task.setName(PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS);
        task.setDescription(PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS_DESCRIPTION);
        task.setTaskClass(CloseStalePullRequestsTask.class.getName());
        task.setStartTime(DateUtils.addMinutes(new Date(), 5));
        // once an hour
        task.setRepeatInterval(new Long(3600));
        task.setStartOnStartup(true);
        try {
            schedulerService.scheduleTask(task);
        } catch (SchedulerException e) {
            throw new RuntimeException("Failed to schedule close stale pull requests task", e);
        }
    } else {
        boolean anyChanges = GeneralUtils.setPropertyIfDifferent(task, "description", PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS_DESCRIPTION);
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "taskClass", CloseStalePullRequestsTask.class.getName());
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "repeatInterval", new Long(3600));
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "startOnStartup", true);
        if (anyChanges) {
            schedulerService.saveTaskDefinition(task);
        }
        if (!task.getStarted()) {
            task.setStarted(true);
            try {
                schedulerService.scheduleTask(task);
            } catch (SchedulerException e) {
                throw new RuntimeException("Failed to schedule close stale pull requests task", e);
            }
        }
    }
}
Also used : SchedulerService(org.openmrs.scheduler.SchedulerService) TaskDefinition(org.openmrs.scheduler.TaskDefinition) CloseStalePullRequestsTask(org.openmrs.module.paperrecord.CloseStalePullRequestsTask) SchedulerException(org.openmrs.scheduler.SchedulerException) Date(java.util.Date)

Example 5 with SchedulerService

use of org.openmrs.scheduler.SchedulerService in project openmrs-module-mirebalais by PIH.

the class ArchivesSetup method setupCloseStaleCreateRequestsTask.

public static void setupCloseStaleCreateRequestsTask() {
    SchedulerService schedulerService = Context.getSchedulerService();
    TaskDefinition task = schedulerService.getTaskByName(PaperRecordConstants.TASK_CLOSE_STALE_CREATE_REQUESTS);
    if (task == null) {
        task = new TaskDefinition();
        task.setName(PaperRecordConstants.TASK_CLOSE_STALE_CREATE_REQUESTS);
        task.setDescription(PaperRecordConstants.TASK_CLOSE_STALE_CREATE_REQUESTS_DESCRIPTION);
        task.setTaskClass(CloseStaleCreateRequestsTask.class.getName());
        task.setStartTime(DateUtils.addMinutes(new Date(), 5));
        // once an hour
        task.setRepeatInterval(new Long(3600));
        task.setStartOnStartup(true);
        try {
            schedulerService.scheduleTask(task);
        } catch (SchedulerException e) {
            throw new RuntimeException("Failed to schedule close stale create requests task", e);
        }
    } else {
        boolean anyChanges = GeneralUtils.setPropertyIfDifferent(task, "description", PaperRecordConstants.TASK_CLOSE_STALE_CREATE_REQUESTS_DESCRIPTION);
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "taskClass", CloseStaleCreateRequestsTask.class.getName());
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "repeatInterval", new Long(3600));
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "startOnStartup", true);
        if (anyChanges) {
            schedulerService.saveTaskDefinition(task);
        }
        if (!task.getStarted()) {
            task.setStarted(true);
            try {
                schedulerService.scheduleTask(task);
            } catch (SchedulerException e) {
                throw new RuntimeException("Failed to schedule close stale create requests task", e);
            }
        }
    }
}
Also used : SchedulerService(org.openmrs.scheduler.SchedulerService) TaskDefinition(org.openmrs.scheduler.TaskDefinition) SchedulerException(org.openmrs.scheduler.SchedulerException) CloseStaleCreateRequestsTask(org.openmrs.module.paperrecord.CloseStaleCreateRequestsTask) Date(java.util.Date)

Aggregations

SchedulerService (org.openmrs.scheduler.SchedulerService)7 TaskDefinition (org.openmrs.scheduler.TaskDefinition)7 Date (java.util.Date)6 SchedulerException (org.openmrs.scheduler.SchedulerException)6 MarkAppointmentsAsMissedOrCompletedTask (org.openmrs.module.mirebalais.task.MarkAppointmentsAsMissedOrCompletedTask)1 CloseStaleCreateRequestsTask (org.openmrs.module.paperrecord.CloseStaleCreateRequestsTask)1 CloseStalePullRequestsTask (org.openmrs.module.paperrecord.CloseStalePullRequestsTask)1 PihCloseStaleVisitsTask (org.openmrs.module.pihcore.task.PihCloseStaleVisitsTask)1 UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts (org.openmrs.module.pihcore.task.UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts)1