private ProcessToolSchedulerService getSchedulerService() {
return registry.getRegisteredService(ProcessToolSchedulerService.class);
}
private void scheduleDeadline(String processInternalId, ProcessDeadline pd) {
ProcessToolSchedulerService service = getSchedulerService();
Date currentDate = new Date(), dueDate = pd.getDueDate();
if (DateUtils.isSameDay(dueDate, currentDate) || currentDate.before(dueDate) || !pd.isAlreadyProcessed()) {
JobDataMap dataMap = new JobDataMap();
dataMap.put("processInstanceId", processInternalId);
dataMap.put("deadlineAttribute", pd);
dataMap.put("deadlineEngine", this);
String taskName = pd.getTaskName();
String identity = "pi:" + processInternalId + ";task:" + taskName;
JobDetail jobDetail = JobBuilder.newJob(HandleDeadlineJob.class)
.withIdentity(identity, HandleDeadlineJob.class.getName())
.usingJobData(dataMap)
.build();
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(identity, HandleDeadlineJob.class.getName())
.startAt(dueDate)
.forJob(jobDetail)
.build();
logger.info("Scheduling deadline job handler at: " + dueDate + " for process instance: " + processInternalId
+ " and task name: " + taskName);
service.scheduleJob(jobDetail, trigger);
}
}