use of org.openmrs.scheduler.SchedulerException 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.SchedulerException 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);
}
}
}
}
use of org.openmrs.scheduler.SchedulerException in project openmrs-module-mirebalais by PIH.
the class AppointmentSchedulingSetup method setupMarkAppointmentAsMissedOrCompletedTask.
public static void setupMarkAppointmentAsMissedOrCompletedTask() {
SchedulerService schedulerService = Context.getSchedulerService();
TaskDefinition task = schedulerService.getTaskByName(MirebalaisConstants.TASK_MARK_APPOINTMENTS_AS_MISSED_OR_COMPLETED);
if (task == null) {
task = new TaskDefinition();
task.setName(MirebalaisConstants.TASK_MARK_APPOINTMENTS_AS_MISSED_OR_COMPLETED);
task.setDescription(MirebalaisConstants.TASK_MARK_APPOINTMENTS_AS_MISSED_OR_COMPLETED_DESCRIPTION);
task.setTaskClass(MarkAppointmentsAsMissedOrCompletedTask.class.getName());
// doesn't really do anything since start on startup = true
task.setStartTime(DateUtils.addMinutes(new Date(), 5));
task.setRepeatInterval(MirebalaisConstants.TASK_MARK_APPOINTMENTS_AS_MISSED_OR_COMPLETED_REPEAT_INTERVAL);
task.setStartOnStartup(true);
try {
schedulerService.scheduleTask(task);
} catch (SchedulerException e) {
throw new RuntimeException("Failed to schedule mark appointments as missed or completed task", e);
}
} else {
boolean anyChanges = GeneralUtils.setPropertyIfDifferent(task, "description", MirebalaisConstants.TASK_MARK_APPOINTMENTS_AS_MISSED_OR_COMPLETED_DESCRIPTION);
anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "taskClass", MarkAppointmentsAsMissedOrCompletedTask.class.getName());
// we can't pass in the constant directly for some reason because it is static
anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "repeatInterval", MirebalaisConstants.TASK_MARK_APPOINTMENTS_AS_MISSED_OR_COMPLETED_REPEAT_INTERVAL);
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 mark appointments as missed or completed task", e);
}
}
}
}
Aggregations