Search in sources :

Example 16 with Job

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

the class ProcessDefinitionInfoComponent method initSuspensionStateInformation.

protected void initSuspensionStateInformation() {
    List<Job> jobs = managementService.createJobQuery().processDefinitionId(processDefinition.getId()).orderByJobDuedate().asc().list();
    List<JobEntity> suspensionStateJobs = new ArrayList<JobEntity>();
    // TODO: this is a hack (ie the cast to JobEntity)... we must clean this in the engine!
    for (Job job : jobs) {
        JobEntity jobEntity = (JobEntity) job;
        if (jobEntity.getJobHandlerType().equals(TimerSuspendProcessDefinitionHandler.TYPE) || jobEntity.getJobHandlerType().equals(TimerActivateProcessDefinitionHandler.TYPE)) {
            suspensionStateJobs.add(jobEntity);
        }
    }
    if (!suspensionStateJobs.isEmpty()) {
        // Header
        Label suspensionStateTitle = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_SUSPENSION_STATE));
        suspensionStateTitle.addStyleName(ExplorerLayout.STYLE_H3);
        addComponent(suspensionStateTitle);
        addEmptySpace(this);
        // Actual suspend/activation jobs
        for (JobEntity jobEntity : suspensionStateJobs) {
            if (jobEntity.getJobHandlerType().equals(TimerSuspendProcessDefinitionHandler.TYPE)) {
                Label suspendLabel = new Label(i18nManager.getMessage(Messages.PROCESS_SCHEDULED_SUSPEND, Constants.DEFAULT_TIME_FORMATTER.format(jobEntity.getDuedate())), Label.CONTENT_XHTML);
                addComponent(suspendLabel);
            } else if (jobEntity.getJobHandlerType().equals(TimerActivateProcessDefinitionHandler.TYPE)) {
                Label suspendLabel = new Label(i18nManager.getMessage(Messages.PROCESS_SCHEDULED_ACTIVATE, Constants.DEFAULT_TIME_FORMATTER.format(jobEntity.getDuedate())), Label.CONTENT_XHTML);
                addComponent(suspendLabel);
            }
        }
    }
    addEmptySpace(this);
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) ArrayList(java.util.ArrayList) Label(com.vaadin.ui.Label) Job(org.activiti.engine.runtime.Job)

Example 17 with Job

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

the class ActiveProcessDefinitionDetailPanel method initActions.

protected void initActions(final AbstractPage parentPage) {
    ActiveProcessDefinitionPage processDefinitionPage = (ActiveProcessDefinitionPage) parentPage;
    Button suspendButton = new Button(i18nManager.getMessage(Messages.PROCESS_SUSPEND));
    suspendButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            ChangeProcessSuspensionStatePopupWindow popupWindow = new ChangeProcessSuspensionStatePopupWindow(processDefinition.getId(), parentPage, true);
            ExplorerApp.get().getViewManager().showPopupWindow(popupWindow);
        }
    });
    // Check if button must be disabled
    boolean suspendJobPending = false;
    List<Job> jobs = ProcessEngines.getDefaultProcessEngine().getManagementService().createJobQuery().processDefinitionId(processDefinition.getId()).list();
    for (Job job : jobs) {
        // TODO: this is a hack. Needs to be cleaner in engine!
        if (((JobEntity) job).getJobHandlerType().equals(TimerSuspendProcessDefinitionHandler.TYPE)) {
            suspendJobPending = true;
            break;
        }
    }
    suspendButton.setEnabled(!suspendJobPending);
    // Clear toolbar and add 'start' button
    processDefinitionPage.getToolBar().removeAllButtons();
    processDefinitionPage.getToolBar().addButton(suspendButton);
}
Also used : Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) Job(org.activiti.engine.runtime.Job) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 18 with Job

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

the class ProcessInstanceSuspensionTest method testJobNotExecutedAfterProcessInstanceSuspend.

@Deployment
public void testJobNotExecutedAfterProcessInstanceSuspend() {
    Date now = new Date();
    processEngineConfiguration.getClock().setCurrentTime(now);
    // Suspending the process instance should also stop the execution of jobs for that process instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    assertEquals(1, managementService.createJobQuery().count());
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    assertEquals(1, managementService.createJobQuery().count());
    // The jobs should not be executed now
    // Timer is set to fire on 5 minutes
    processEngineConfiguration.getClock().setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000)));
    Job job = managementService.createJobQuery().executable().singleResult();
    assertNull(job);
    assertEquals(1, managementService.createJobQuery().count());
    // Activation of the process instance should now allow for job execution
    runtimeService.activateProcessInstanceById(processInstance.getId());
    waitForJobExecutorToProcessAllJobs(1000L, 100L);
    assertEquals(0, managementService.createJobQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 19 with Job

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

the class JobExceptionStacktraceResource method getJobStacktrace.

@RequestMapping(value = "/management/jobs/{jobId}/exception-stacktrace", method = RequestMethod.GET)
public String getJobStacktrace(@PathVariable String jobId, HttpServletResponse response) {
    Job job = getJobFromResponse(jobId);
    String stackTrace = managementService.getJobExceptionStacktrace(job.getId());
    if (stackTrace == null) {
        throw new ActivitiObjectNotFoundException("Job with id '" + job.getId() + "' doesn't have an exception stacktrace.", String.class);
    }
    response.setContentType("text/plain");
    return stackTrace;
}
Also used : Job(org.activiti.engine.runtime.Job) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with Job

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

the class TimerEventsAndNewVersionDeploymentsTest method testTimerRestoreOnDeploymentDelete1.

public void testTimerRestoreOnDeploymentDelete1() {
    String deploymentId1 = deployTimerProcess();
    // Process has same key
    String deploymentId2 = deployProcessWithoutTimers();
    String deploymentId3 = deployTimerProcess();
    String deploymentId4 = deployProcessWithoutTimers();
    assertTimerJobs(0);
    repositoryService.deleteDeployment(deploymentId4, true);
    assertTimerJobs(1);
    Job job = managementService.createJobQuery().singleResult();
    assertEquals(repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId3).singleResult().getId(), job.getProcessDefinitionId());
    cleanup(deploymentId1, deploymentId2, deploymentId3);
}
Also used : Job(org.activiti.engine.runtime.Job)

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