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);
}
}
}
}
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);
}
}
}
}
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);
}
}
}
}
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);
}
}
}
}
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);
}
}
}
}
Aggregations