use of org.wso2.carbon.humantask.core.api.scheduler.InvalidUpdateRequestException in project carbon-business-process by wso2.
the class SimpleScheduler method updateJob.
/**
* Update the schedule time for a job
*
* @param taskId Task ID
* @param scheduledTime Time to be updated
* @param name Name of the task
*/
public void updateJob(Long taskId, String name, Long scheduledTime) throws InvalidJobsInDbException, InvalidUpdateRequestException {
long now = System.currentTimeMillis();
if (now > scheduledTime) {
String errMessage = "Current time: " + now + " > request time: " + scheduledTime;
throw new InvalidUpdateRequestException(errMessage);
}
boolean immediate = scheduledTime <= now + immediateInterval;
boolean nearfuture = !immediate && scheduledTime <= now + nearFutureInterval;
Long jobId = getConnection().updateJob(taskId, name, immediate, nearfuture, nodeId, scheduledTime);
if (jobId > -1) {
// one job is found
todo.dequeue(new Job(jobId));
// We ignore if the job is not in the Map outstandingJobs
outstandingJobs.remove(jobId);
// Loading/Refresh the job here, in-order to update the job for the latest changes.
// Otherwise when the next immediate load task runs, it still fetch the job with the
// old updates.
ParameterizedType genericSuperClass = (ParameterizedType) getConnection().getClass().getGenericSuperclass();
Class entityClass = (Class) genericSuperClass.getActualTypeArguments()[0];
HumanTaskJobDAO updatedJob = (HumanTaskJobDAO) getEntityManager().find(entityClass, jobId);
getEntityManager().refresh(updatedJob);
if (immediate) {
// Immediate scheduling means we add the job immediately to the todo list and
// we put it in the DB for safe keeping
addTodoList(new Job(updatedJob));
} else if (nearfuture) {
// Re-schedule load-immediate job task
todo.clearTasks(LoadImmediateTask.class);
todo.dequeue(new Job(jobId));
// We ignore if the job is not in the Map outstandingJobs
outstandingJobs.remove(jobId);
todo.enqueue(new LoadImmediateTask(System.currentTimeMillis() + 1000));
} else {
todo.clearTasks(UpgradeJobsTask.class);
todo.enqueue(new UpgradeJobsTask(System.currentTimeMillis() + 1000));
}
}
}
Aggregations