protected TimerEntity createTweetTimer(String msg, Date duedate) { TimerEntity timer = new TimerEntity(); timer.setJobHandlerType("tweet"); timer.setJobHandlerConfigurationRaw(msg); timer.setDuedate(duedate); return timer; }
public void schedule(TimerEntity timer) { Date duedate = timer.getDuedate(); ensureNotNull("duedate", duedate); timer.insert(); hintJobExecutorIfNeeded(timer, duedate); }
public Void execute(CommandContext commandContext) { JobManager jobManager = commandContext.getJobManager(); timerEntity = new TimerEntity(); timerEntity.setLockOwner(UUID.randomUUID().toString()); timerEntity.setDuedate(new Date()); timerEntity.setRetries(0); timerEntity.setExceptionMessage("I'm supposed to fail"); jobManager.insert(timerEntity); assertNotNull(timerEntity.getId()); return null; } });
protected TimerEntity newJobInstance(ExecutionEntity execution) { TimerEntity timer = new TimerEntity(this); if (execution != null) { timer.setExecution(execution); } return timer; }
public Void execute(CommandContext commandContext) { TimerEntity failedJob = (TimerEntity) commandContext .getJobManager() .findJobById(jobId); Date newDueDate = failedJob.calculateRepeat(); if (newDueDate != null) { failedJob.createNewTimerJob(newDueDate); // update configuration of failed job TimerJobConfiguration config = (TimerJobConfiguration) failedJob.getJobHandlerConfiguration(); config.setFollowUpJobCreated(true); failedJob.setJobHandlerConfiguration(config); } return null; }
public Void execute(CommandContext commandContext) { JobManager jobManager = commandContext.getJobManager(); timerEntity = new TimerEntity(); timerEntity.setLockOwner(UUID.randomUUID().toString()); timerEntity.setDuedate(new Date()); timerEntity.setRetries(0); StringWriter stringWriter = new StringWriter(); NullPointerException exception = new NullPointerException(); exception.printStackTrace(new PrintWriter(stringWriter)); timerEntity.setExceptionStacktrace(stringWriter.toString()); jobManager.insert(timerEntity); assertNotNull(timerEntity.getId()); return null; } });
@Override protected void preExecute(CommandContext commandContext) { if (getJobHandler() instanceof TimerEventJobHandler) { TimerJobConfiguration configuration = (TimerJobConfiguration) getJobHandlerConfiguration(); if (repeat != null && !configuration.isFollowUpJobCreated()) { // this timer is a repeating timer and // a follow up timer job has not been scheduled yet Date newDueDate = calculateRepeat(); if (newDueDate != null) { // the listener is added to the transaction as SYNC on ROLLABCK, // when it is necessary to schedule a new timer job invocation. // If the transaction does not rollback, it is ignored. ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequiresNew(); RepeatingFailedJobListener listener = createRepeatingFailedJobListener(commandExecutor); commandContext.getTransactionContext().addTransactionListener( TransactionState.ROLLED_BACK, listener); // create a new timer job createNewTimerJob(newDueDate); } } } }
public void createNewTimerJob(Date dueDate) { // create new timer job TimerEntity newTimer = new TimerEntity(this); newTimer.setDuedate(dueDate); Context .getCommandContext() .getJobManager() .schedule(newTimer); }
job.setDuedate(duedate); job.setRepeat(prepared);
public Void execute(CommandContext commandContext) { timerEntity.delete(); commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(timerEntity.getId()); List<HistoricIncident> historicIncidents = Context .getProcessEngineConfiguration() .getHistoryService() .createHistoricIncidentQuery() .list(); for (HistoricIncident historicIncident : historicIncidents) { commandContext .getDbEntityManager() .delete((DbEntity) historicIncident); } return null; } });
protected RepeatingFailedJobListener createRepeatingFailedJobListener(CommandExecutor commandExecutor) { return new RepeatingFailedJobListener(commandExecutor, getId()); }
@Override public JobEntity mapToEntity(ODocument doc, JobEntity entity, OPersistenceSession session) { if(entity==null) { String type = doc.field("type"); if(TimerEntity.TYPE.equals(type)) entity = new TimerEntity(); else if(MessageEntity.TYPE.equals(type)) entity = new MessageEntity(); } entity = super.mapToEntity(doc, entity, session); String exceptionByteArrayId = doc.field("exceptionByteArrayId"); //JobEntity doesn't allow to set exceptionByteArrayId: so lets inject it. //TODO: Fix this behavior if(exceptionByteArrayId!=null) { try { Field field = JobEntity.class.getDeclaredField("exceptionByteArrayId"); field.setAccessible(true); field.set(entity, exceptionByteArrayId); } catch (Exception e) { logger.warn("Setting exceptionByteArrayId doesn't work", e); } } return entity; }
public void cancelTimers(ExecutionEntity execution) { List<TimerEntity> timers = Context .getCommandContext() .getJobManager() .findTimersByExecutionId(execution.getId()); for (TimerEntity timer: timers) { timer.delete(); } }
@Deployment public void testTimerCatchEvent() { Map<String, Object> variables = new HashMap<String, Object>(); Date dueDate = DateTimeUtil.now().plusMinutes(5).toDate(); variables.put("outerVariable", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(dueDate)); runtimeService.startProcessInstanceByKey("testProcess", variables); Job job = managementService.createJobQuery().singleResult(); TimerEntity timer = (TimerEntity) job; assertDateEquals(dueDate, timer.getDuedate()); }
public Void execute(CommandContext commandContext) { JobManager jobManager = commandContext.getJobManager(); timerEntity = new TimerEntity(); timerEntity.setLockOwner(UUID.randomUUID().toString()); timerEntity.setDuedate(new Date()); timerEntity.setRetries(0); StringWriter stringWriter = new StringWriter(); NullPointerException exception = new NullPointerException(); exception.printStackTrace(new PrintWriter(stringWriter)); timerEntity.setExceptionStacktrace(stringWriter.toString()); jobManager.insert(timerEntity); assertNotNull(timerEntity.getId()); return null; } });
@Override protected void preExecute(CommandContext commandContext) { if (getJobHandler() instanceof TimerEventJobHandler) { TimerJobConfiguration configuration = (TimerJobConfiguration) getJobHandlerConfiguration(); if (repeat != null && !configuration.isFollowUpJobCreated()) { // this timer is a repeating timer and // a follow up timer job has not been scheduled yet Date newDueDate = calculateRepeat(); if (newDueDate != null) { // the listener is added to the transaction as SYNC on ROLLABCK, // when it is necessary to schedule a new timer job invocation. // If the transaction does not rollback, it is ignored. ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequiresNew(); RepeatingFailedJobListener listener = createRepeatingFailedJobListener(commandExecutor); commandContext.getTransactionContext().addTransactionListener( TransactionState.ROLLED_BACK, listener); // create a new timer job createNewTimerJob(newDueDate); } } } }
public Void execute(CommandContext commandContext) { TimerEntity failedJob = (TimerEntity) commandContext .getJobManager() .findJobById(jobId); Date newDueDate = failedJob.calculateRepeat(); if (newDueDate != null) { failedJob.createNewTimerJob(newDueDate); // update configuration of failed job TimerJobConfiguration config = (TimerJobConfiguration) failedJob.getJobHandlerConfiguration(); config.setFollowUpJobCreated(true); failedJob.setJobHandlerConfiguration(config); } return null; }
public void createNewTimerJob(Date dueDate) { // create new timer job TimerEntity newTimer = new TimerEntity(this); newTimer.setDuedate(dueDate); Context .getCommandContext() .getJobManager() .schedule(newTimer); }
protected TimerEntity newJobInstance(ExecutionEntity execution) { TimerEntity timer = new TimerEntity(this); if (execution != null) { timer.setExecution(execution); } return timer; }
job.setDuedate(duedate); job.setRepeat(prepared);