Java Code Examples for org.activiti.engine.impl.interceptor.CommandContext#getProcessEngineConfiguration()

The following examples show how to use org.activiti.engine.impl.interceptor.CommandContext#getProcessEngineConfiguration() . 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: TimerSuspendProcessDefinitionHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Job job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
    ProcessEngineConfigurationImpl processEngineConfiguration = commandContext.getProcessEngineConfiguration();

    boolean suspendProcessInstances = false;
    try {
        JsonNode configNode = processEngineConfiguration.getObjectMapper().readTree(configuration);
        suspendProcessInstances = getIncludeProcessInstances(configNode);
    } catch (Exception e) {
        throw new FlowableException("Error reading json value " + configuration, e);
    }

    String processDefinitionId = job.getProcessDefinitionId();

    SuspendProcessDefinitionCmd suspendProcessDefinitionCmd = new SuspendProcessDefinitionCmd(processDefinitionId, null, suspendProcessInstances, null, job.getTenantId());
    suspendProcessDefinitionCmd.execute(commandContext);
}
 
Example 2
Source File: TimerActivateProcessDefinitionHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Job job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
    ProcessEngineConfigurationImpl processEngineConfiguration = commandContext.getProcessEngineConfiguration();

    boolean activateProcessInstances = false;
    try {
        JsonNode configNode = processEngineConfiguration.getObjectMapper().readTree(configuration);
        activateProcessInstances = getIncludeProcessInstances(configNode);
    } catch (Exception e) {
        throw new FlowableException("Error reading json value " + configuration, e);
    }

    String processDefinitionId = job.getProcessDefinitionId();

    ActivateProcessDefinitionCmd activateProcessDefinitionCmd = new ActivateProcessDefinitionCmd(processDefinitionId, null, activateProcessInstances, null, job.getTenantId());
    activateProcessDefinitionCmd.execute(commandContext);
}
 
Example 3
Source File: JobRetryCmd.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Object execute(CommandContext commandContext) {
  JobEntity job = commandContext.getJobEntityManager().findById(jobId);
  if (job == null) {
    return null;
  }

  ProcessEngineConfiguration processEngineConfig = commandContext.getProcessEngineConfiguration();

  ExecutionEntity executionEntity = fetchExecutionEntity(commandContext, job.getExecutionId());
  FlowElement currentFlowElement = executionEntity != null ? executionEntity.getCurrentFlowElement() : null;

  String failedJobRetryTimeCycleValue = null;
  if (currentFlowElement instanceof ServiceTask) {
    failedJobRetryTimeCycleValue = ((ServiceTask) currentFlowElement).getFailedJobRetryTimeCycleValue();
  }

  AbstractJobEntity newJobEntity = null;
  if (currentFlowElement == null || failedJobRetryTimeCycleValue == null) {

    log.debug("activity or FailedJobRetryTimerCycleValue is null in job " + jobId + ". only decrementing retries.");
    
    if (job.getRetries() <= 1) {
      newJobEntity = commandContext.getJobManager().moveJobToDeadLetterJob(job);
    } else {
      newJobEntity = commandContext.getJobManager().moveJobToTimerJob(job);
    }
    
    newJobEntity.setRetries(job.getRetries() - 1);
    if (job.getDuedate() == null || JobEntity.JOB_TYPE_MESSAGE.equals(job.getJobType())) {
      // add wait time for failed async job
      newJobEntity.setDuedate(calculateDueDate(commandContext, processEngineConfig.getAsyncFailedJobWaitTime(), null));
    } else {
      // add default wait time for failed job
      newJobEntity.setDuedate(calculateDueDate(commandContext, processEngineConfig.getDefaultFailedJobWaitTime(), job.getDuedate()));
    }

  } else {
    try {
      DurationHelper durationHelper = new DurationHelper(failedJobRetryTimeCycleValue, processEngineConfig.getClock());
      int jobRetries = job.getRetries();
      if (job.getExceptionMessage() == null) {
        // change default retries to the ones configured
        jobRetries = durationHelper.getTimes();
      }
      
      if (jobRetries <= 1) {
        newJobEntity = commandContext.getJobManager().moveJobToDeadLetterJob(job);
      } else {
        newJobEntity = commandContext.getJobManager().moveJobToTimerJob(job);
      }
      
      newJobEntity.setDuedate(durationHelper.getDateAfter());

      if (job.getExceptionMessage() == null) { // is it the first exception
        log.debug("Applying JobRetryStrategy '" + failedJobRetryTimeCycleValue + "' the first time for job " + 
            job.getId() + " with " + durationHelper.getTimes() + " retries");

      } else {
        log.debug("Decrementing retries of JobRetryStrategy '" + failedJobRetryTimeCycleValue + "' for job " + job.getId());
      }
      
      newJobEntity.setRetries(jobRetries - 1);

    } catch (Exception e) {
      throw new ActivitiException("failedJobRetryTimeCylcle has wrong format:" + failedJobRetryTimeCycleValue, exception);
    }
  }
  
  if (exception != null) {
    newJobEntity.setExceptionMessage(exception.getMessage());
    newJobEntity.setExceptionStacktrace(getExceptionStacktrace());
  }

  // Dispatch both an update and a retry-decrement event
  ActivitiEventDispatcher eventDispatcher = commandContext.getEventDispatcher();
  if (eventDispatcher.isEnabled()) {
    eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, newJobEntity));
    eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_RETRIES_DECREMENTED, newJobEntity));
  }

  return null;
}