Search in sources :

Example 26 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class TimerManager method scheduleTimers.

protected void scheduleTimers(ProcessDefinitionEntity processDefinition, Process process) {
    JobManager jobManager = Context.getCommandContext().getJobManager();
    List<TimerJobEntity> timers = getTimerDeclarations(processDefinition, process);
    for (TimerJobEntity timer : timers) {
        jobManager.scheduleTimerJob(timer);
    }
}
Also used : JobManager(org.activiti.engine.impl.asyncexecutor.JobManager) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 27 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class ProcessDefinitionEventsTest method testTimerStartEventDeployment.

/**
 * test sequence of events for process definition with timer start event
 */
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/timer/StartTimerEventTest.testDurationStartTimerEvent.bpmn20.xml" })
public void testTimerStartEventDeployment() {
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionKey("startTimerEventExample").singleResult();
    ActivitiEntityEvent processDefinitionCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, processDefinition);
    TimerJobEntity timer = (TimerJobEntity) managementService.createTimerJobQuery().singleResult();
    ActivitiEntityEvent timerCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, timer);
    assertSequence(processDefinitionCreated, timerCreated);
    listener.clearEventsReceived();
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) Deployment(org.activiti.engine.test.Deployment)

Example 28 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class BoundaryTimerEventRepeatCompatibilityTest method testRepeatWithoutEnd.

@Deployment
public void testRepeatWithoutEnd() throws Throwable {
    Calendar calendar = Calendar.getInstance();
    Date baseTime = calendar.getTime();
    calendar.add(Calendar.MINUTE, 20);
    // expect to stop boundary jobs after 20 minutes
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    DateTime dt = new DateTime(calendar.getTime());
    String dateStr = fmt.print(dt);
    // reset the timer
    Calendar nextTimeCal = Calendar.getInstance();
    nextTimeCal.setTime(baseTime);
    processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("repeatWithEnd");
    runtimeService.setVariable(processInstance.getId(), "EndDateForBoundary", dateStr);
    List<Task> tasks = taskService.createTaskQuery().list();
    assertThat(tasks).hasSize(1);
    Task task = tasks.get(0);
    assertThat(task.getName()).isEqualTo("Task A");
    // Test Boundary Events
    // complete will cause timer to be created
    taskService.complete(task.getId());
    List<Job> jobs = managementService.createTimerJobQuery().list();
    assertThat(jobs).hasSize(1);
    // change the job in old mode (the configuration should not be json in
    // "old mode" but a simple string).
    TimerJobEntity job = (TimerJobEntity) jobs.get(0);
    changeConfigurationToPlainText(job);
    // boundary events
    waitForJobExecutorToProcessAllJobs(2000, 100);
    // a new job must be prepared because there are 10 repeats 2 seconds interval
    jobs = managementService.createTimerJobQuery().list();
    assertThat(jobs).hasSize(1);
    for (int i = 0; i < 9; i++) {
        nextTimeCal.add(Calendar.SECOND, 2);
        processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
        waitForJobExecutorToProcessAllJobs(2000, 100);
        // a new job must be prepared because there are 10 repeats 2 seconds interval
        jobs = managementService.createTimerJobQuery().list();
        assertThat(jobs).hasSize(1);
    }
    nextTimeCal.add(Calendar.SECOND, 2);
    processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
    } catch (Exception ex) {
        fail("Should not have any other jobs because the endDate is reached");
    }
    tasks = taskService.createTaskQuery().list();
    task = tasks.get(0);
    assertThat(task.getName()).isEqualTo("Task B");
    assertThat(tasks).hasSize(1);
    taskService.complete(task.getId());
    try {
        waitForJobExecutorToProcessAllJobs(2000, 500);
    } catch (Exception e) {
        fail("No jobs should be active here.");
    }
    // now All the process instances should be completed
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
    assertThat(processInstances).hasSize(0);
    // no jobs
    jobs = managementService.createJobQuery().list();
    assertThat(jobs).hasSize(0);
    jobs = managementService.createTimerJobQuery().list();
    assertThat(jobs).hasSize(0);
    // no tasks
    tasks = taskService.createTaskQuery().list();
    assertThat(tasks).hasSize(0);
}
Also used : Task(org.activiti.engine.task.Task) Calendar(java.util.Calendar) Date(java.util.Date) DateTime(org.joda.time.DateTime) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) Deployment(org.activiti.engine.test.Deployment)

Aggregations

TimerJobEntity (org.activiti.engine.impl.persistence.entity.TimerJobEntity)28 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)8 SuspendedJobEntity (org.activiti.engine.impl.persistence.entity.SuspendedJobEntity)7 DeadLetterJobEntity (org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity)6 Deployment (org.activiti.engine.test.Deployment)6 AbstractJobEntity (org.activiti.engine.impl.persistence.entity.AbstractJobEntity)5 Job (org.activiti.engine.runtime.Job)5 ActivitiException (org.activiti.engine.ActivitiException)4 JobManager (org.activiti.engine.impl.asyncexecutor.JobManager)4 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)4 Date (java.util.Date)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 Calendar (java.util.Calendar)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 VariableScope (org.activiti.engine.delegate.VariableScope)2 Page (org.activiti.engine.impl.Page)2 AcquiredTimerJobEntities (org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities)2 AcquireTimerJobsCmd (org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)2 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)2