Search in sources :

Example 1 with TimerJobEntity

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

the class ProcessInstanceSuspensionTest method testJobsNotVisibleToAcquisitionIfInstanceSuspended.

@Deployment(resources = { "org/activiti/engine/test/db/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisibleToAcquisitionIfInstanceSuspended() {
    ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance pi = runtimeService.startProcessInstanceByKey(pd.getKey());
    // now there is one job:
    Job job = managementService.createTimerJobQuery().singleResult();
    assertThat(job).isNotNull();
    makeSureJobDue(job);
    // the acquirejobs command sees the job:
    List<TimerJobEntity> acquiredJobs = executeAcquireJobsCommand();
    assertThat(acquiredJobs).hasSize(1);
    // suspend the process instance:
    runtimeService.suspendProcessInstanceById(pi.getId());
    // now, the acquirejobs command does not see the job:
    acquiredJobs = executeAcquireJobsCommand();
    assertThat(acquiredJobs).hasSize(0);
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) Deployment(org.activiti.engine.test.Deployment)

Example 2 with TimerJobEntity

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

the class ProcessInstanceSuspensionTest method testJobsNotVisibleToAcquisitionIfDefinitionSuspended.

@Deployment(resources = { "org/activiti/engine/test/db/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisibleToAcquisitionIfDefinitionSuspended() {
    ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(pd.getKey());
    // now there is one job:
    Job job = managementService.createTimerJobQuery().singleResult();
    assertThat(job).isNotNull();
    makeSureJobDue(job);
    // the acquire jobs command sees the job:
    List<TimerJobEntity> acquiredJobs = executeAcquireJobsCommand();
    assertThat(acquiredJobs).hasSize(1);
    // suspend the process instance:
    repositoryService.suspendProcessDefinitionById(pd.getId(), true, null);
    // now, the acquire jobs command does not see the job:
    acquiredJobs = executeAcquireJobsCommand();
    assertThat(acquiredJobs).hasSize(0);
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Job(org.activiti.engine.runtime.Job) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) Deployment(org.activiti.engine.test.Deployment)

Example 3 with TimerJobEntity

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

the class JobExecutorTestCase method createTweetTimer.

protected TimerJobEntity createTweetTimer(String msg, Date duedate) {
    TimerJobEntity timer = new TimerJobEntityImpl();
    timer.setJobType(JobEntity.JOB_TYPE_TIMER);
    timer.setJobHandlerType("tweet");
    timer.setJobHandlerConfiguration(msg);
    timer.setDuedate(duedate);
    return timer;
}
Also used : TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) TimerJobEntityImpl(org.activiti.engine.impl.persistence.entity.TimerJobEntityImpl)

Example 4 with TimerJobEntity

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

the class TimerEventCompatibilityTest method changeConfigurationToPlainText.

protected void changeConfigurationToPlainText(TimerJobEntity job) {
    String activityId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
    final TimerJobEntity finalJob = job;
    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
    CommandConfig config = new CommandConfig().transactionNotSupported();
    final String finalActivityId = activityId;
    commandExecutor.execute(config, new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            DbSqlSession session = commandContext.getDbSqlSession();
            session.delete(finalJob);
            session.flush();
            session.commit();
            return null;
        }
    });
    commandExecutor.execute(config, new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            DbSqlSession session = commandContext.getDbSqlSession();
            finalJob.setJobHandlerConfiguration(finalActivityId);
            finalJob.setId(null);
            session.insert(finalJob);
            session.flush();
            session.commit();
            return null;
        }
    });
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 5 with TimerJobEntity

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

the class AbstractSetProcessInstanceStateCmd method execute.

public Void execute(CommandContext commandContext) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("ProcessInstanceId cannot be null.");
    }
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(processInstanceId);
    if (executionEntity == null) {
        throw new ActivitiObjectNotFoundException("Cannot find processInstance for id '" + processInstanceId + "'.", Execution.class);
    }
    if (!executionEntity.isProcessInstanceType()) {
        throw new ActivitiException("Cannot set suspension state for execution '" + processInstanceId + "': not a process instance.");
    }
    SuspensionStateUtil.setSuspensionState(executionEntity, getNewState());
    commandContext.getExecutionEntityManager().update(executionEntity, false);
    // All child executions are suspended
    Collection<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByProcessInstanceId(processInstanceId);
    for (ExecutionEntity childExecution : childExecutions) {
        if (!childExecution.getId().equals(processInstanceId)) {
            SuspensionStateUtil.setSuspensionState(childExecution, getNewState());
            commandContext.getExecutionEntityManager().update(childExecution, false);
        }
    }
    // All tasks are suspended
    List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByProcessInstanceId(processInstanceId);
    for (TaskEntity taskEntity : tasks) {
        SuspensionStateUtil.setSuspensionState(taskEntity, getNewState());
        commandContext.getTaskEntityManager().update(taskEntity, false);
    }
    // All jobs are suspended
    if (getNewState() == SuspensionState.ACTIVE) {
        List<SuspendedJobEntity> suspendedJobs = commandContext.getSuspendedJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
        for (SuspendedJobEntity suspendedJob : suspendedJobs) {
            commandContext.getJobManager().activateSuspendedJob(suspendedJob);
        }
    } else {
        List<TimerJobEntity> timerJobs = commandContext.getTimerJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
        for (TimerJobEntity timerJob : timerJobs) {
            commandContext.getJobManager().moveJobToSuspendedJob(timerJob);
        }
        List<JobEntity> jobs = commandContext.getJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
        for (JobEntity job : jobs) {
            commandContext.getJobManager().moveJobToSuspendedJob(job);
        }
    }
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

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