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;
}
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;
}
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());
}
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());
}
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());
}
Aggregations