Search in sources :

Example 1 with AcquiredTimerJobEntities

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

the class AcquireTimerJobsCmd method execute.

public AcquiredTimerJobEntities execute(CommandContext commandContext) {
    AcquiredTimerJobEntities acquiredJobs = new AcquiredTimerJobEntities();
    List<TimerJobEntity> timerJobs = commandContext.getTimerJobEntityManager().findTimerJobsToExecute(new Page(0, asyncExecutor.getMaxAsyncJobsDuePerAcquisition()));
    for (TimerJobEntity job : timerJobs) {
        lockJob(commandContext, job, asyncExecutor.getAsyncJobLockTimeInMillis());
        acquiredJobs.addJob(job);
    }
    return acquiredJobs;
}
Also used : Page(org.activiti.engine.impl.Page) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) AcquiredTimerJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities)

Example 2 with AcquiredTimerJobEntities

use of org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities 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));
    AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    String jobId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            TimerJobEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
            commandContext.getJobManager().scheduleTimerJob(timer);
            return timer.getId();
        }
    });
    AcquiredTimerJobEntities acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd(asyncExecutor));
    assertThat(acquiredJobs.size()).isEqualTo(0);
    processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
    acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd(asyncExecutor));
    assertThat(acquiredJobs.size()).isEqualTo(1);
    TimerJobEntity job = acquiredJobs.getJobs().iterator().next();
    assertThat(job.getId()).isEqualTo(jobId);
    assertThat(tweetHandler.getMessages()).hasSize(0);
    Job executableJob = managementService.moveTimerToExecutableJob(jobId);
    commandExecutor.execute(new ExecuteAsyncJobCmd(executableJob.getId()));
    assertThat(tweetHandler.getMessages().get(0)).isEqualTo("i'm coding a test");
    assertThat(tweetHandler.getMessages()).hasSize(1);
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ExecuteAsyncJobCmd(org.activiti.engine.impl.cmd.ExecuteAsyncJobCmd) Job(org.activiti.engine.runtime.Job) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) Date(java.util.Date) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor) AcquiredTimerJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities) AcquireTimerJobsCmd(org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)

Aggregations

AcquiredTimerJobEntities (org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities)2 TimerJobEntity (org.activiti.engine.impl.persistence.entity.TimerJobEntity)2 Date (java.util.Date)1 Page (org.activiti.engine.impl.Page)1 AsyncExecutor (org.activiti.engine.impl.asyncexecutor.AsyncExecutor)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 Job (org.activiti.engine.runtime.Job)1