use of org.activiti.engine.impl.persistence.entity.TimerJobEntityManager in project Activiti by Activiti.
the class DefaultJobManager method executeTimerJob.
protected void executeTimerJob(JobEntity timerEntity) {
TimerJobEntityManager timerJobEntityManager = processEngineConfiguration.getTimerJobEntityManager();
VariableScope variableScope = null;
if (timerEntity.getExecutionId() != null) {
variableScope = getExecutionEntityManager().findById(timerEntity.getExecutionId());
}
if (variableScope == null) {
variableScope = NoExecutionVariableScope.getSharedInstance();
}
// set endDate if it was set to the definition
restoreExtraData(timerEntity, variableScope);
if (timerEntity.getDuedate() != null && !isValidTime(timerEntity, timerEntity.getDuedate(), variableScope)) {
if (logger.isDebugEnabled()) {
logger.debug("Timer {} fired. but the dueDate is after the endDate. Deleting timer.", timerEntity.getId());
}
processEngineConfiguration.getJobEntityManager().delete(timerEntity);
return;
}
executeJobHandler(timerEntity);
processEngineConfiguration.getJobEntityManager().delete(timerEntity);
if (logger.isDebugEnabled()) {
logger.debug("Timer {} fired. Deleting timer.", timerEntity.getId());
}
if (timerEntity.getRepeat() != null) {
TimerJobEntity newTimerJobEntity = timerJobEntityManager.createAndCalculateNextTimer(timerEntity, variableScope);
if (newTimerJobEntity != null) {
scheduleTimerJob(newTimerJobEntity);
}
}
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntityManager in project Activiti by Activiti.
the class DestroyScopeOperation method deleteAllScopeJobs.
private void deleteAllScopeJobs(ExecutionEntity scopeExecution, TimerJobEntityManager timerJobEntityManager) {
Collection<TimerJobEntity> timerJobsForExecution = timerJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
for (TimerJobEntity job : timerJobsForExecution) {
timerJobEntityManager.delete(job);
}
JobEntityManager jobEntityManager = commandContext.getJobEntityManager();
Collection<JobEntity> jobsForExecution = jobEntityManager.findJobsByExecutionId(scopeExecution.getId());
for (JobEntity job : jobsForExecution) {
jobEntityManager.delete(job);
}
SuspendedJobEntityManager suspendedJobEntityManager = commandContext.getSuspendedJobEntityManager();
Collection<SuspendedJobEntity> suspendedJobsForExecution = suspendedJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
for (SuspendedJobEntity job : suspendedJobsForExecution) {
suspendedJobEntityManager.delete(job);
}
DeadLetterJobEntityManager deadLetterJobEntityManager = commandContext.getDeadLetterJobEntityManager();
Collection<DeadLetterJobEntity> deadLetterJobsForExecution = deadLetterJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
for (DeadLetterJobEntity job : deadLetterJobsForExecution) {
deadLetterJobEntityManager.delete(job);
}
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntityManager in project Activiti by Activiti.
the class DestroyScopeOperation method run.
@Override
public void run() {
// Find the actual scope that needs to be destroyed.
// This could be the incoming execution, or the first parent execution where isScope = true
// Find parent scope execution
ExecutionEntity scopeExecution = execution.isScope() ? execution : findFirstParentScopeExecution(execution);
if (scopeExecution == null) {
throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
}
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
deleteAllChildExecutions(executionEntityManager, scopeExecution);
// Delete all scope tasks
TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
deleteAllScopeTasks(scopeExecution, taskEntityManager);
// Delete all scope jobs
TimerJobEntityManager timerJobEntityManager = commandContext.getTimerJobEntityManager();
deleteAllScopeJobs(scopeExecution, timerJobEntityManager);
// Remove variables associated with this scope
VariableInstanceEntityManager variableInstanceEntityManager = commandContext.getVariableInstanceEntityManager();
removeAllVariablesFromScope(scopeExecution, variableInstanceEntityManager);
commandContext.getHistoryManager().recordActivityEnd(scopeExecution, scopeExecution.getDeleteReason());
executionEntityManager.delete(scopeExecution);
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntityManager in project Activiti by Activiti.
the class JobExecutorTest method testBasicJobExecutorOperation.
public void testBasicJobExecutorOperation() throws Exception {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
JobManager jobManager = commandContext.getJobManager();
jobManager.execute(createTweetMessage("message-one"));
jobManager.execute(createTweetMessage("message-two"));
jobManager.execute(createTweetMessage("message-three"));
jobManager.execute(createTweetMessage("message-four"));
TimerJobEntityManager timerJobManager = commandContext.getTimerJobEntityManager();
timerJobManager.insert(createTweetTimer("timer-one", new Date()));
timerJobManager.insert(createTweetTimer("timer-one", new Date()));
timerJobManager.insert(createTweetTimer("timer-two", new Date()));
return null;
}
});
GregorianCalendar currentCal = new GregorianCalendar();
currentCal.add(Calendar.MINUTE, 1);
processEngineConfiguration.getClock().setCurrentTime(currentCal.getTime());
waitForJobExecutorToProcessAllJobs(50000L, 200L);
Set<String> messages = new HashSet<String>(tweetHandler.getMessages());
Set<String> expectedMessages = new HashSet<String>();
expectedMessages.add("message-one");
expectedMessages.add("message-two");
expectedMessages.add("message-three");
expectedMessages.add("message-four");
expectedMessages.add("timer-one");
expectedMessages.add("timer-two");
assertThat(new TreeSet<String>(messages)).isEqualTo(new TreeSet<String>(expectedMessages));
}
Aggregations