Search in sources :

Example 1 with AcquiredJobEntities

use of org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities in project Activiti by Activiti.

the class AcquireAsyncJobsDueCmd method execute.

public AcquiredJobEntities execute(CommandContext commandContext) {
    AcquiredJobEntities acquiredJobs = new AcquiredJobEntities();
    List<JobEntity> jobs = commandContext.getJobEntityManager().findAsyncJobsDueToExecute(new Page(0, asyncExecutor.getMaxAsyncJobsDuePerAcquisition()));
    for (JobEntity job : jobs) {
        lockJob(commandContext, job, asyncExecutor.getAsyncJobLockTimeInMillis());
        acquiredJobs.addJob(job);
    }
    return acquiredJobs;
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) Page(org.activiti.engine.impl.Page)

Example 2 with AcquiredJobEntities

use of org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities in project Activiti by Activiti.

the class AcquireTimerJobsCmd method execute.

public AcquiredJobEntities execute(CommandContext commandContext) {
    AcquiredJobEntities acquiredJobs = new AcquiredJobEntities();
    List<JobEntity> jobs = commandContext.getJobEntityManager().findNextTimerJobsToExecute(new Page(0, maxJobsPerAcquisition));
    for (JobEntity job : jobs) {
        if (job != null && !acquiredJobs.contains(job.getId())) {
            lockJob(commandContext, job, lockOwner, lockTimeInMillis);
            acquiredJobs.addJob(job);
        }
    }
    return acquiredJobs;
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) Page(org.activiti.engine.impl.Page)

Example 3 with AcquiredJobEntities

use of org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testJobsNotVisisbleToAcquisitionIfDefinitionSuspended.

@Deployment(resources = { "org/activiti/engine/test/db/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisisbleToAcquisitionIfDefinitionSuspended() {
    ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(pd.getKey());
    // now there is one job:
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    makeSureJobDue(job);
    // the acquirejobs command sees the job:
    AcquiredJobEntities acquiredJobs = executeAcquireJobsCommand();
    assertEquals(1, acquiredJobs.size());
    // suspend the process instance:
    repositoryService.suspendProcessDefinitionById(pd.getId());
    // now, the acquirejobs command does not see the job:
    acquiredJobs = executeAcquireJobsCommand();
    assertEquals(0, acquiredJobs.size());
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 4 with AcquiredJobEntities

use of org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities in project Activiti by Activiti.

the class JobExecutorCmdHappyTest method testJobCommandsWithTimer.

public void testJobCommandsWithTimer() {
    // clock gets automatically reset in LogTestCase.runTest
    processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME));
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    String jobId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            TimerEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
            commandContext.getJobEntityManager().schedule(timer);
            return timer.getId();
        }
    });
    AcquiredJobEntities acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd("testLockOwner", 10000, 5));
    assertEquals(0, acquiredJobs.size());
    processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
    acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd("testLockOwner", 10000, 5));
    assertEquals(1, acquiredJobs.size());
    JobEntity job = acquiredJobs.getJobs().iterator().next();
    assertEquals(jobId, job.getId());
    assertEquals(0, tweetHandler.getMessages().size());
    commandExecutor.execute(new ExecuteAsyncJobCmd(job));
    assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
    assertEquals(1, tweetHandler.getMessages().size());
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ExecuteAsyncJobCmd(org.activiti.engine.impl.cmd.ExecuteAsyncJobCmd) Date(java.util.Date) AcquireTimerJobsCmd(org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)

Example 5 with AcquiredJobEntities

use of org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testJobsNotVisisbleToAcquisitionIfInstanceSuspended.

@Deployment(resources = { "org/activiti/engine/test/db/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisisbleToAcquisitionIfInstanceSuspended() {
    ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance pi = runtimeService.startProcessInstanceByKey(pd.getKey());
    // now there is one job:
    // now there is one job:
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    makeSureJobDue(job);
    // the acquirejobs command sees the job:
    AcquiredJobEntities acquiredJobs = executeAcquireJobsCommand();
    assertEquals(1, acquiredJobs.size());
    // suspend the process instance:
    runtimeService.suspendProcessInstanceById(pi.getId());
    // now, the acquirejobs command does not see the job:
    acquiredJobs = executeAcquireJobsCommand();
    assertEquals(0, acquiredJobs.size());
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Aggregations

AcquiredJobEntities (org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities)5 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)3 Page (org.activiti.engine.impl.Page)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 Job (org.activiti.engine.runtime.Job)2 Deployment (org.activiti.engine.test.Deployment)2 Date (java.util.Date)1 AcquireTimerJobsCmd (org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)1 ExecuteAsyncJobCmd (org.activiti.engine.impl.cmd.ExecuteAsyncJobCmd)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)1 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1