Search in sources :

Example 71 with Job

use of org.activiti.engine.runtime.Job in project Activiti by Activiti.

the class JobListQuery method loadItems.

public List<Item> loadItems(int start, int count) {
    List<Job> jobs = managementService.createJobQuery().orderByJobDuedate().asc().orderByJobId().asc().list();
    List<Item> items = new ArrayList<Item>();
    for (Job job : jobs) {
        items.add(new JobListItem(job));
    }
    return items;
}
Also used : PropertysetItem(com.vaadin.data.util.PropertysetItem) Item(com.vaadin.data.Item) ArrayList(java.util.ArrayList) Job(org.activiti.engine.runtime.Job)

Example 72 with Job

use of org.activiti.engine.runtime.Job in project Activiti by Activiti.

the class RestResponseFactory method createJobResponseList.

public List<JobResponse> createJobResponseList(List<Job> jobs) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    List<JobResponse> responseList = new ArrayList<JobResponse>();
    for (Job instance : jobs) {
        responseList.add(createJobResponse(instance, urlBuilder));
    }
    return responseList;
}
Also used : ArrayList(java.util.ArrayList) JobResponse(org.activiti.rest.service.api.management.JobResponse) Job(org.activiti.engine.runtime.Job)

Example 73 with Job

use of org.activiti.engine.runtime.Job in project Activiti by Activiti.

the class JobEventsTest method testJobEntityEventsException.

/**
	 * Test create, update and delete events of jobs entities.
	 */
@Deployment
public void testJobEntityEventsException() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJobEvents");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Set retries to 1, to prevent multiple chains of events being thrown
    managementService.setJobRetries(theJob.getId(), 1);
    listener.clearEventsReceived();
    // Force timer to fire
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DAY_OF_YEAR, 1);
    processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
    try {
        managementService.executeJob(theJob.getId());
        fail("Expected exception");
    } catch (Exception e) {
    // exception expected
    }
    // Check delete-event has been dispatched
    assertEquals(5, listener.getEventsReceived().size());
    // First, the timer was fired
    ActivitiEvent event = listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.TIMER_FIRED, event.getType());
    checkEventContext(event, theJob, true);
    // Second, the job-entity was deleted, as the job was executed
    event = listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
    checkEventContext(event, theJob, true);
    // Next, a job failed event is dispatched
    event = listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.JOB_EXECUTION_FAILURE, event.getType());
    checkEventContext(event, theJob, true);
    // Finally, an update-event is received and the job count is decremented
    event = listener.getEventsReceived().get(3);
    assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
    checkEventContext(event, theJob, true);
    event = listener.getEventsReceived().get(4);
    assertEquals(ActivitiEventType.JOB_RETRIES_DECREMENTED, event.getType());
    assertEquals(0, ((Job) ((ActivitiEntityEvent) event).getEntity()).getRetries());
    checkEventContext(event, theJob, true);
}
Also used : Calendar(java.util.Calendar) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 74 with Job

use of org.activiti.engine.runtime.Job in project Activiti by Activiti.

the class JobEventsTest method testRepetitionJobEntityEvents.

/**
   * Timer repetition
   */
@Deployment
public void testRepetitionJobEntityEvents() throws Exception {
    Clock previousClock = processEngineConfiguration.getClock();
    Clock testClock = new DefaultClockImpl();
    processEngineConfiguration.setClock(testClock);
    Date now = new Date();
    testClock.setCurrentTime(now);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testRepetitionJobEvents");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Check if create-event has been dispatched
    assertEquals(2, listener.getEventsReceived().size());
    ActivitiEvent event = listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    checkEventContext(event, theJob, false);
    event = listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    checkEventContext(event, theJob, false);
    listener.clearEventsReceived();
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
        fail("a new job must be prepared because there are 2 repeats");
    } catch (Exception ex) {
    //expected exception because a new job is prepared
    }
    testClock.setCurrentTime(new Date(now.getTime() + 10000L));
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
        fail("a new job must be prepared because there are 2 repeats");
    } catch (Exception ex) {
    //expected exception because a new job is prepared
    }
    testClock.setCurrentTime(new Date(now.getTime() + 20000L));
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
    } catch (Exception ex) {
        fail("There must be no jobs remaining");
    }
    testClock.setCurrentTime(new Date(now.getTime() + 30000L));
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
    } catch (Exception ex) {
        fail("There must be no jobs remaining");
    }
    // count timer fired events
    int timerFiredCount = 0;
    List<ActivitiEvent> eventsReceived = listener.getEventsReceived();
    for (ActivitiEvent eventReceived : eventsReceived) {
        if (ActivitiEventType.TIMER_FIRED.equals(eventReceived.getType())) {
            timerFiredCount++;
        }
    }
    listener.clearEventsReceived();
    processEngineConfiguration.setClock(previousClock);
    assertEquals(2, timerFiredCount);
}
Also used : DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Clock(org.activiti.engine.runtime.Clock) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 75 with Job

use of org.activiti.engine.runtime.Job in project Activiti by Activiti.

the class JobEventsTest method testJobCanceledEventByManagementService.

@Deployment(resources = "org/activiti/engine/test/api/event/JobEventsTest.testJobCanceledEventOnBoundaryEvent.bpmn20.xml")
public void testJobCanceledEventByManagementService() throws Exception {
    // GIVEN
    processEngineConfiguration.getClock().setCurrentTime(new Date());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testTimerCancelledEvent");
    listener.clearEventsReceived();
    Job job = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    // WHEN
    managementService.deleteJob(job.getId());
    // THEN
    checkEventCount(1, ActivitiEventType.JOB_CANCELED);
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Job (org.activiti.engine.runtime.Job)110 Deployment (org.activiti.engine.test.Deployment)76 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)55 Task (org.activiti.engine.task.Task)39 Date (java.util.Date)23 Calendar (java.util.Calendar)16 DelegateTask (org.activiti.engine.delegate.DelegateTask)11 HashMap (java.util.HashMap)10 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)10 JobQuery (org.activiti.engine.runtime.JobQuery)8 ActivitiException (org.activiti.engine.ActivitiException)6 SimpleDateFormat (java.text.SimpleDateFormat)5 ArrayList (java.util.ArrayList)5 DefaultClockImpl (org.activiti.engine.impl.util.DefaultClockImpl)5 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)5 Clock (org.activiti.engine.runtime.Clock)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4