use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class TimerSchedulerServiceImpl method restoreFromMemento.
/**
*/
@Override
@SuppressWarnings("unchecked")
public void restoreFromMemento(OpenmrsMemento memento) {
if (memento != null && memento instanceof TimerSchedulerMemento) {
TimerSchedulerMemento timerMemento = (TimerSchedulerMemento) memento;
Set<Integer> taskIds = (HashSet<Integer>) timerMemento.getState();
// try to start all of the tasks that were stopped right before this restore
for (Integer taskId : taskIds) {
TaskDefinition task = getTask(taskId);
try {
scheduleTask(task);
} catch (Exception e) {
// essentially swallow exceptions
log.debug("EXPECTED ERROR IF STOPPING THIS TASK'S MODULE: Unable to start task " + taskId, e);
// save this errored task and try again next time we restore
timerMemento.addErrorTask(taskId);
}
}
}
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class TimerSchedulerServiceImpl method saveToMemento.
/**
* Saves and stops all active tasks
*
* @return OpenmrsMemento
*/
@Override
public OpenmrsMemento saveToMemento() {
Set<Integer> tasks = new HashSet<>();
for (TaskDefinition task : getScheduledTasks()) {
tasks.add(task.getId());
try {
shutdownTask(task);
} catch (SchedulerException e) {
// just swallow exceptions
log.debug("Failed to stop task while saving memento " + task.getName(), e);
}
}
TimerSchedulerMemento memento = new TimerSchedulerMemento(tasks);
memento.saveErrorTasks();
return memento;
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class TimerSchedulerServiceImpl method getScheduledTasks.
/**
* Get all scheduled tasks.
*
* @return all scheduled tasks
*/
@Override
public Collection<TaskDefinition> getScheduledTasks() {
// The real list of scheduled tasks is kept up-to-date in the scheduledTasks map
// TODO change the index for the scheduledTasks map to be the TaskDefinition rather than the ID
List<TaskDefinition> list = new ArrayList<>();
if (scheduledTasks != null) {
Set<Integer> taskIds = scheduledTasks.keySet();
for (Integer id : taskIds) {
TaskDefinition task = getTask(id);
log.debug("Adding scheduled task " + id + " to list (" + task.getRepeatInterval() + ")");
list.add(task);
}
}
return list;
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class HibernateSchedulerDAO method deleteTask.
/**
* Delete task from database.
*
* @param taskId <code>Integer</code> identifier of task to be deleted
* @throws DAOException
*/
@Override
public void deleteTask(Integer taskId) throws DAOException {
TaskDefinition taskConfig = getTask(taskId);
deleteTask(taskConfig);
}
use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.
the class HibernateSchedulerDAO method getTaskByName.
/**
* Get task by public name.
*
* @param name public task name
* @return task with given public name
* @throws DAOException
*/
@Override
public TaskDefinition getTaskByName(String name) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(TaskDefinition.class).add(Restrictions.eq("name", name));
TaskDefinition task = (TaskDefinition) crit.uniqueResult();
if (task == null) {
log.warn("Task '" + name + "' not found");
throw new ObjectRetrievalFailureException(TaskDefinition.class, name);
}
return task;
}
Aggregations