org.activiti.engine.impl.persistence.entity.JobEntity Java Examples

The following examples show how to use org.activiti.engine.impl.persistence.entity.JobEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobExecutorCmdHappyTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testJobCommandsWithMessage() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();

  String jobId = commandExecutor.execute(new Command<String>() {

    public String execute(CommandContext commandContext) {
      JobEntity message = createTweetMessage("i'm coding a test");
      commandContext.getJobManager().scheduleAsyncJob(message);
      return message.getId();
    }
  });

  Job job = managementService.createJobQuery().singleResult();
  assertNotNull(job);
  assertEquals(jobId, job.getId());

  assertEquals(0, tweetHandler.getMessages().size());

  managementService.executeJob(job.getId());

  assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
  assertEquals(1, tweetHandler.getMessages().size());
}
 
Example #2
Source File: ResetExpiredJobsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void assertJobDetails(boolean locked) {
  JobQuery jobQuery = managementService.createJobQuery();
  
  if (locked) {
    jobQuery.locked(); 
  }
  
  Job job = jobQuery.singleResult();
  assertTrue(job instanceof JobEntity);
  JobEntity jobEntity = (JobEntity) job;
  
  if (locked) {
    assertNotNull(jobEntity.getLockOwner());
    assertNotNull(jobEntity.getLockExpirationTime());
  } else {
    assertNull(jobEntity.getLockOwner());
    assertNull(jobEntity.getLockExpirationTime());
  }
}
 
Example #3
Source File: ActivityEventsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/activiti/engine/test/bpmn/event/timer/BoundaryTimerEventTest.testTimerOnNestingOfSubprocesses.bpmn20.xml")
public void testActivityTimeOutEventInSubProcess() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnNestedSubprocesses");
    Job theJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);

    // Force timer to fire
    Calendar timeToFire = Calendar.getInstance();
    timeToFire.add(Calendar.HOUR, 2);
    timeToFire.add(Calendar.SECOND, 5);
    processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
    waitForJobExecutorToProcessAllJobs(2000, 200);

    // Check timeout-events have been dispatched
    assertEquals(3, listener.getEventsReceived().size());
    List<String> eventIdList = new ArrayList<String>();
    for (FlowableEvent event : listener.getEventsReceived()) {
        assertEquals(FlowableEngineEventType.ACTIVITY_CANCELLED, event.getType());
        assertTrue("TIMER is the cause of the cancellation", ((FlowableActivityCancelledEvent) event).getCause() instanceof JobEntity);
        eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
    }
    assertTrue(eventIdList.indexOf("innerTask1") >= 0);
    assertTrue(eventIdList.indexOf("innerTask2") >= 0);
    assertTrue(eventIdList.indexOf("innerFork") >= 0);
}
 
Example #4
Source File: ActivityEventsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testActivityTimeOutEventInCallActivity() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnCallActivity");
    Job theJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);

    // Force timer to fire
    Calendar timeToFire = Calendar.getInstance();
    timeToFire.add(Calendar.HOUR, 2);
    timeToFire.add(Calendar.SECOND, 5);
    processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
    waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(10000, 500);

    // Check timeout-events have been dispatched
    assertEquals(4, listener.getEventsReceived().size());
    List<String> eventIdList = new ArrayList<String>();
    for (FlowableEvent event : listener.getEventsReceived()) {
        assertEquals(FlowableEngineEventType.ACTIVITY_CANCELLED, event.getType());
        assertTrue("TIMER is the cause of the cancellation", ((FlowableActivityCancelledEvent) event).getCause() instanceof JobEntity);
        eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
    }
    assertTrue(eventIdList.indexOf("innerTask1") >= 0);
    assertTrue(eventIdList.indexOf("innerTask2") >= 0);
    assertTrue(eventIdList.indexOf("innerFork") >= 0);
    assertTrue(eventIdList.indexOf("callActivity") >= 0);
}
 
Example #5
Source File: ActivityEventsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/activiti/engine/test/api/event/JobEventsTest.testJobEntityEvents.bpmn20.xml")
public void testActivityTimeOutEvent() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJobEvents");
    Job theJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);

    // Force timer to fire
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DAY_OF_YEAR, 1);
    processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
    waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(2000, 100);

    // Check timeout has been dispatched
    assertEquals(1, listener.getEventsReceived().size());
    FlowableEvent activitiEvent = listener.getEventsReceived().get(0);
    assertEquals("ACTIVITY_CANCELLED event expected", FlowableEngineEventType.ACTIVITY_CANCELLED, activitiEvent.getType());
    FlowableActivityCancelledEvent cancelledEvent = (FlowableActivityCancelledEvent) activitiEvent;
    assertTrue("TIMER is the cause of the cancellation", cancelledEvent.getCause() instanceof JobEntity);
}
 
Example #6
Source File: DefaultJobManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public JobEntity moveDeadLetterJobToExecutableJob(DeadLetterJobEntity deadLetterJobEntity, int retries) {
  if (deadLetterJobEntity == null) {
    throw new ActivitiIllegalArgumentException("Null job provided");
  }
  
  JobEntity executableJob = createExecutableJobFromOtherJob(deadLetterJobEntity);
  executableJob.setRetries(retries);
  boolean insertSuccesful = processEngineConfiguration.getJobEntityManager().insertJobEntity(executableJob);
  if (insertSuccesful) {
    processEngineConfiguration.getDeadLetterJobEntityManager().delete(deadLetterJobEntity);
    triggerExecutorIfNeeded(executableJob);
    return executableJob;
  }
  return null;
}
 
Example #7
Source File: ExecuteAsyncRunnable.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void run() {
  
  if (job == null) {
    job = processEngineConfiguration.getCommandExecutor().execute(new Command<JobEntity>() {
      @Override
      public JobEntity execute(CommandContext commandContext) {
        return commandContext.getJobEntityManager().findById(jobId);
      }
    });
  }
  
  if (isHandledByActiviti5Engine()) {
    return;
  }
  
  boolean lockNotNeededOrSuccess = lockJobIfNeeded();

  if (lockNotNeededOrSuccess) {
    executeJob();
    unlockJobIfNeeded();
  }

}
 
Example #8
Source File: JobQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
private void createJobWithoutExceptionStacktrace() {
    CommandExecutor commandExecutor = (CommandExecutor) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawCommandExecutor();
    commandExecutor.execute(new Command<Void>() {
        public Void execute(CommandContext commandContext) {
            JobEntityManager jobManager = commandContext.getJobEntityManager();

            jobEntity = new JobEntity();
            jobEntity.setJobType(Job.JOB_TYPE_MESSAGE);
            jobEntity.setRevision(1);
            jobEntity.setLockOwner(UUID.randomUUID().toString());
            jobEntity.setRetries(0);
            jobEntity.setExceptionMessage("I'm supposed to fail");

            jobManager.insert(jobEntity);

            assertNotNull(jobEntity.getId());

            return null;

        }
    });

}
 
Example #9
Source File: AbstractSetProcessDefinitionStateCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void createTimerForDelayedExecution(CommandContext commandContext, List<ProcessDefinitionEntity> processDefinitions) {
  for (ProcessDefinitionEntity processDefinition : processDefinitions) {
    
    if (Activiti5Util.isActiviti5ProcessDefinition(commandContext, processDefinition)) continue;
    
    TimerJobEntity timer = commandContext.getTimerJobEntityManager().create();
    timer.setJobType(JobEntity.JOB_TYPE_TIMER);
    timer.setProcessDefinitionId(processDefinition.getId());

    // Inherit tenant identifier (if applicable)
    if (processDefinition.getTenantId() != null) {
      timer.setTenantId(processDefinition.getTenantId());
    }

    timer.setDuedate(executionDate);
    timer.setJobHandlerType(getDelayedExecutionJobHandlerType());
    timer.setJobHandlerConfiguration(TimerChangeProcessDefinitionSuspensionStateJobHandler.createJobHandlerConfiguration(includeProcessInstances));
    commandContext.getJobManager().scheduleTimerJob(timer);
  }
}
 
Example #10
Source File: MoveDeadLetterJobToExecutableJobCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public JobEntity execute(CommandContext commandContext) {

    if (jobId == null) {
      throw new ActivitiIllegalArgumentException("jobId and job is null");
    }

    DeadLetterJobEntity job = commandContext.getDeadLetterJobEntityManager().findById(jobId);
    if (job == null) {
      throw new JobNotFoundException(jobId);
    }

    if (log.isDebugEnabled()) {
      log.debug("Moving deadletter job to executable job table {}", job.getId());
    }
    
    return commandContext.getJobManager().moveDeadLetterJobToExecutableJob(job, retries);
  }
 
Example #11
Source File: DefaultActiviti5CompatibilityHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected org.activiti5.engine.impl.persistence.entity.JobEntity convertToActiviti5JobEntity(final JobEntity job, final ProcessEngineConfigurationImpl processEngineConfiguration) {
  org.activiti5.engine.impl.persistence.entity.JobEntity activity5Job = new org.activiti5.engine.impl.persistence.entity.JobEntity();
  activity5Job.setJobType(job.getJobType());
  activity5Job.setDuedate(job.getDuedate());
  activity5Job.setExclusive(job.isExclusive());
  activity5Job.setExecutionId(job.getExecutionId());
  activity5Job.setId(job.getId());
  activity5Job.setJobHandlerConfiguration(job.getJobHandlerConfiguration());
  activity5Job.setJobHandlerType(job.getJobHandlerType());
  activity5Job.setEndDate(job.getEndDate());
  activity5Job.setRepeat(job.getRepeat());
  activity5Job.setProcessDefinitionId(job.getProcessDefinitionId());
  activity5Job.setProcessInstanceId(job.getProcessInstanceId());
  activity5Job.setRetries(job.getRetries());
  activity5Job.setRevision(job.getRevision());
  activity5Job.setTenantId(job.getTenantId());
  activity5Job.setExceptionMessage(job.getExceptionMessage());
  return activity5Job;
}
 
Example #12
Source File: HerdCommandInvoker.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the JobEntity from the given ExecuteAsyncJobCmd.
 *
 * @param executeAsyncJobCmd The ExecuteAsyncJobCmd
 *
 * @return The JobEntity
 */
private JobEntity getJobEntity(ExecuteAsyncJobCmd executeAsyncJobCmd)
{
    /*
     * Unfortunately, ExecuteAsyncJobCmd does not provide an accessible method to get the JobEntity stored within it.
     * We use reflection to force the value out of the object.
     * Also, we cannot simply get the entity and update it. We must retrieve it through the entity manager so it registers in Activiti's persistent object
     * cache. This way when the transaction commits, Activiti is aware of any changes in the JobEntity and persists them correctly.
     */
    try
    {
        Field field = ExecuteAsyncJobCmd.class.getDeclaredField("job");
        ReflectionUtils.makeAccessible(field);
        String jobId = ((JobEntity) ReflectionUtils.getField(field, executeAsyncJobCmd)).getId();

        return Context.getCommandContext().getJobEntityManager().findJobById(jobId);
    }
    catch (NoSuchFieldException | SecurityException e)
    {
        /*
         * This exception should not happen.
         */
        throw new IllegalStateException(e);
    }
}
 
Example #13
Source File: ActivityEventsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/activiti/engine/test/bpmn/event/timer/BoundaryTimerEventTest.testTimerOnNestingOfSubprocesses.bpmn20.xml")
public void testActivityTimeOutEventInSubProcess() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnNestedSubprocesses");
  Job theJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
  assertNotNull(theJob);

  // Force timer to fire
  Calendar timeToFire = Calendar.getInstance();
  timeToFire.add(Calendar.HOUR, 2);
  timeToFire.add(Calendar.SECOND, 5);
  processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
  waitForJobExecutorToProcessAllJobs(2000, 200);

  // Check timeout-events have been dispatched
  assertEquals(4, listener.getEventsReceived().size());
  List<String> eventIdList = new ArrayList<String>();
  for (ActivitiEvent event : listener.getEventsReceived()) {
    assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, event.getType());
    assertTrue("TIMER is the cause of the cancellation", ((ActivitiActivityCancelledEvent) event).getCause() instanceof JobEntity);
    eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
  }
  assertTrue(eventIdList.indexOf("innerTask1") >= 0);
  assertTrue(eventIdList.indexOf("innerTask2") >= 0);
  assertTrue(eventIdList.indexOf("subprocess") >= 0);
  assertTrue(eventIdList.indexOf("innerSubprocess") >= 0);
}
 
Example #14
Source File: HerdCommandInvokerTest.java    From herd with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteWithExceptionAndGetJobEntityWithSecurityException()
{
    // Mock dependencies.
    CommandConfig config = mock(CommandConfig.class);
    JobEntity jobEntity = mock(JobEntity.class);
    ExecuteAsyncJobCmd command = new ExecuteAsyncJobCmd(jobEntity);
    doThrow(SecurityException.class).when(jobEntity).getId();

    // Try to call the method under test.
    try
    {
        herdCommandInvoker.execute(config, command);
        fail();
    }
    catch (IllegalStateException e)
    {
        assertEquals(SecurityException.class.getName(), e.getMessage());
    }
}
 
Example #15
Source File: TimerSuspendProcessDefinitionHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(JobEntity job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
  JSONObject cfgJson = new JSONObject(configuration);
  String processDefinitionId = job.getProcessDefinitionId();
  boolean suspendProcessInstances = getIncludeProcessInstances(cfgJson);

  SuspendProcessDefinitionCmd suspendProcessDefinitionCmd = new SuspendProcessDefinitionCmd(processDefinitionId, null, suspendProcessInstances, null, job.getTenantId());
  suspendProcessDefinitionCmd.execute(commandContext);
}
 
Example #16
Source File: AsyncTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testFailingAsyncServiceTimer() { 
  // start process 
  runtimeService.startProcessInstanceByKey("asyncService");
  // now there should be one job in the database, and it is a message
  assertEquals(1, managementService.createJobQuery().count());
  Job job = managementService.createJobQuery().singleResult();
  if (!JobEntity.JOB_TYPE_MESSAGE.equals(job.getJobType())) {
    fail("the job must be a message");
  }      
  
  try {
    managementService.executeJob(job.getId());
    fail();
  } catch (Exception e) {
    // exception expected
  }
  
  // the service failed: the execution is still sitting in the service task:
  Execution execution = runtimeService.createExecutionQuery().singleResult();
  assertNotNull(execution);
  assertEquals("service", runtimeService.getActiveActivityIds(execution.getId()).get(0));
  
  // there is still a single job because the timer was created in the same transaction as the 
  // service was executed (which rolled back)
  assertEquals(1, managementService.createTimerJobQuery().count());    
  
  runtimeService.deleteProcessInstance(execution.getId(), "dead");        
}
 
Example #17
Source File: DeleteJobCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
    JobEntity jobToDelete = getJobToDelete(commandContext);

    jobToDelete.delete();
    return null;
}
 
Example #18
Source File: TriggerTimerEventJobHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(JobEntity job, String configuration, ExecutionEntity execution, CommandContext commandContext) {

    Context.getAgenda().planTriggerExecutionOperation(execution);

    if (commandContext.getEventDispatcher().isEnabled()) {
      commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TIMER_FIRED, job));
    }

    if (execution.getCurrentFlowElement() instanceof BoundaryEvent) {
      List<String> processedElements = new ArrayList<String>();
      dispatchExecutionTimeOut(job, execution, processedElements, commandContext);
    }
  }
 
Example #19
Source File: ExecuteAsyncJobCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {

    if (job == null) {
        throw new ActivitiIllegalArgumentException("job is null");
    }

    // We need to refetch the job, as it could have been deleted by another concurrent job
    // For example: an embedded subprocess with a couple of async tasks and a timer on the boundary of the subprocess
    // when the timer fires, all executions and thus also the jobs inside of the embedded subprocess are destroyed.
    // However, the async task jobs could already have been fetched and put in the queue.... while in reality they have been deleted.
    // A refetch is thus needed here to be sure that it exists for this transaction.

    JobEntity refetchedJob = commandContext.getJobEntityManager().findJobById(job.getId());
    if (refetchedJob == null) {
        LOGGER.debug("Job does not exist anymore and will not be executed. It has most likely been deleted "
                + "as part of another concurrent part of the process instance.");
        return null;
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Executing async job {}", refetchedJob.getId());
    }

    refetchedJob.execute(commandContext);

    if (commandContext.getEventDispatcher().isEnabled()) {
        commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(
                FlowableEngineEventType.JOB_EXECUTION_SUCCESS, refetchedJob));
    }

    return null;
}
 
Example #20
Source File: ExclusiveTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testNonExclusiveService() {
  // start process
  runtimeService.startProcessInstanceByKey("exclusive");
  // now there should be 1 non-exclusive job in the database:
  Job job = managementService.createJobQuery().singleResult();
  assertNotNull(job);
  assertFalse(((JobEntity) job).isExclusive());

  waitForJobExecutorToProcessAllJobs(6000L, 100L);

  // all the jobs are done
  assertEquals(0, managementService.createJobQuery().count());
}
 
Example #21
Source File: CancelJobsCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {
  JobEntity jobToDelete = null;
  for (String jobId : jobIds) {
    jobToDelete = commandContext.getJobEntityManager().findById(jobId);

    if (jobToDelete != null) {
      // When given job doesn't exist, ignore
      if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, jobToDelete));
      }

      commandContext.getJobEntityManager().delete(jobToDelete);
    
    } else {
      TimerJobEntity timerJobToDelete = commandContext.getTimerJobEntityManager().findById(jobId);

      if (timerJobToDelete != null) {
        // When given job doesn't exist, ignore
        if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
          commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, timerJobToDelete));
        }

        commandContext.getTimerJobEntityManager().delete(timerJobToDelete);
      }
    }
  }
  return null;
}
 
Example #22
Source File: AcquireJobsCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public AcquiredJobEntities execute(CommandContext commandContext) {
  AcquiredJobEntities acquiredJobs = new AcquiredJobEntities();
  List<JobEntity> jobs = commandContext.getJobEntityManager().findJobsToExecute(new Page(0, asyncExecutor.getMaxAsyncJobsDuePerAcquisition()));

  for (JobEntity job : jobs) {
    lockJob(commandContext, job, asyncExecutor.getAsyncJobLockTimeInMillis());
    acquiredJobs.addJob(job);
  }

  return acquiredJobs;
}
 
Example #23
Source File: AcquireJobsCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void lockJob(CommandContext commandContext, JobEntity job, int lockTimeInMillis) {
  GregorianCalendar gregorianCalendar = new GregorianCalendar();
  gregorianCalendar.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
  gregorianCalendar.add(Calendar.MILLISECOND, lockTimeInMillis);
  job.setLockOwner(asyncExecutor.getLockOwner());
  job.setLockExpirationTime(gregorianCalendar.getTime());
}
 
Example #24
Source File: IntermediateCatchTimerEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void eventCancelledByEventGateway(DelegateExecution execution) {
  JobEntityManager jobEntityManager = Context.getCommandContext().getJobEntityManager();
  List<JobEntity> jobEntities = jobEntityManager.findJobsByExecutionId(execution.getId());
  
  for (JobEntity jobEntity : jobEntities) { // Should be only one
    jobEntityManager.delete(jobEntity);
  }
  
  Context.getCommandContext().getExecutionEntityManager().deleteExecutionAndRelatedData((ExecutionEntity) execution, 
      DeleteReason.EVENT_BASED_GATEWAY_CANCEL, false);
}
 
Example #25
Source File: JobExecutorTestCase.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected JobEntity createTweetMessage(String msg) {
    JobEntity message = new JobEntity();
    message.setJobType(Job.JOB_TYPE_MESSAGE);
    message.setRevision(1);
    message.setJobHandlerType("tweet");
    message.setJobHandlerConfiguration(msg);
    return message;
}
 
Example #26
Source File: DefaultJobManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected JobEntity createExecutableJobFromOtherJob(AbstractJobEntity job) {
  JobEntity executableJob = processEngineConfiguration.getJobEntityManager().create();
  copyJobInfo(executableJob, job);
  
  if (isAsyncExecutorActive()) {
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTime(processEngineConfiguration.getClock().getCurrentTime());
    gregorianCalendar.add(Calendar.MILLISECOND, getAsyncExecutor().getTimerLockTimeInMillis());
    executableJob.setLockExpirationTime(gregorianCalendar.getTime());
    executableJob.setLockOwner(getAsyncExecutor().getLockOwner());
  }
  
  return executableJob;
}
 
Example #27
Source File: DefaultJobManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void fillDefaultAsyncJobInfo(JobEntity jobEntity, ExecutionEntity execution, boolean exclusive) {
  jobEntity.setJobType(JobEntity.JOB_TYPE_MESSAGE);
  jobEntity.setRevision(1);
  jobEntity.setRetries(processEngineConfiguration.getAsyncExecutorNumberOfRetries());
  jobEntity.setExecutionId(execution.getId());
  jobEntity.setProcessInstanceId(execution.getProcessInstanceId());
  jobEntity.setProcessDefinitionId(execution.getProcessDefinitionId());
  jobEntity.setExclusive(exclusive);
  jobEntity.setJobHandlerType(AsyncContinuationJobHandler.TYPE);
  
  // Inherit tenant id (if applicable)
  if (execution.getTenantId() != null) {
    jobEntity.setTenantId(execution.getTenantId());
  }
}
 
Example #28
Source File: DefaultJobManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected JobEntity internalCreateLockedAsyncJob(ExecutionEntity execution, boolean exclusive) {
  JobEntity asyncJob = processEngineConfiguration.getJobEntityManager().create();
  fillDefaultAsyncJobInfo(asyncJob, execution, exclusive);
  
  GregorianCalendar gregorianCalendar = new GregorianCalendar();
  gregorianCalendar.setTime(processEngineConfiguration.getClock().getCurrentTime());
  gregorianCalendar.add(Calendar.MILLISECOND, getAsyncExecutor().getAsyncJobLockTimeInMillis());
  asyncJob.setLockExpirationTime(gregorianCalendar.getTime());
  asyncJob.setLockOwner(getAsyncExecutor().getLockOwner());
  
  return asyncJob;
}
 
Example #29
Source File: CancelJobsCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    JobEntity jobToDelete = null;
    for (String jobId : jobIds) {
        jobToDelete = commandContext
                .getJobEntityManager()
                .findJobById(jobId);

        if (jobToDelete != null) {
            if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.JOB_CANCELED, jobToDelete));
            }

            jobToDelete.delete();

        } else {
            TimerJobEntity timerJobToDelete = commandContext.getTimerJobEntityManager().findJobById(jobId);

            if (timerJobToDelete != null) {
                if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                    commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                            ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.JOB_CANCELED, timerJobToDelete));
                }

                timerJobToDelete.delete();
            }
        }
    }
    return null;
}
 
Example #30
Source File: SpringAsyncExecutor.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean executeAsyncJob(Job job) {
  try {
    taskExecutor.execute(new ExecuteAsyncRunnable((JobEntity) job, processEngineConfiguration));
    return true;
  } catch (RejectedExecutionException e) {
    rejectedJobsHandler.jobRejected(this, job);
    return false;
  }
}