Search in sources :

Example 41 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class JobQueryTest method setRetries.

// helper ////////////////////////////////////////////////////////////
private void setRetries(final String processInstanceId, final int retries) {
    final Job job = managementService.createJobQuery().processInstanceId(processInstanceId).singleResult();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            JobEntity timer = commandContext.getDbEntityManager().selectById(JobEntity.class, job.getId());
            timer.setRetries(retries);
            return null;
        }
    });
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Job(org.camunda.bpm.engine.runtime.Job)

Example 42 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class BatchMigrationTest method testDeleteBatchJobManually.

@Test
public void testDeleteBatchJobManually() {
    // given
    Batch batch = helper.createMigrationBatchWithSize(1);
    helper.executeSeedJob(batch);
    JobEntity migrationJob = (JobEntity) helper.getExecutionJobs(batch).get(0);
    String byteArrayId = migrationJob.getJobHandlerConfigurationRaw();
    ByteArrayEntity byteArrayEntity = engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired().execute(new GetByteArrayCommand(byteArrayId));
    assertNotNull(byteArrayEntity);
    // when
    managementService.deleteJob(migrationJob.getId());
    // then
    byteArrayEntity = engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired().execute(new GetByteArrayCommand(byteArrayId));
    assertNull(byteArrayEntity);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) Batch(org.camunda.bpm.engine.batch.Batch) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 43 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class JobEntityTest method testJobExceptionMessageCutoff.

public void testJobExceptionMessageCutoff() {
    JobEntity threeByteJobEntity = new MessageEntity();
    String message = repeatCharacter("a", JobEntity.MAX_EXCEPTION_MESSAGE_LENGTH * 2);
    threeByteJobEntity.setExceptionMessage(message);
    assertEquals(JobEntity.MAX_EXCEPTION_MESSAGE_LENGTH, threeByteJobEntity.getExceptionMessage().length());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)

Example 44 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class HistoryCleanupJobHandler method execute.

@Override
public void execute(HistoryCleanupJobHandlerConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
    // find JobEntity
    JobEntity jobEntity = commandContext.getJobManager().findJobByHandlerType(getType());
    boolean rescheduled = false;
    if (configuration.isImmediatelyDue() || (HistoryCleanupHelper.isBatchWindowConfigured(commandContext) && HistoryCleanupHelper.isWithinBatchWindow(ClockUtil.getCurrentTime(), commandContext))) {
        // find data to delete
        final HistoryCleanupBatch nextBatch = HistoryCleanupHelper.getNextBatch(commandContext);
        if (nextBatch.size() >= getBatchSizeThreshold(commandContext)) {
            // delete bunch of data
            nextBatch.performCleanup();
            // reschedule now
            commandContext.getJobManager().reschedule(jobEntity, ClockUtil.getCurrentTime());
            rescheduled = true;
            cancelCountEmptyRuns(configuration, jobEntity);
        } else {
            // still have something to delete
            if (nextBatch.size() > 0) {
                nextBatch.performCleanup();
            }
            // not enough data for cleanup was found
            if (HistoryCleanupHelper.isWithinBatchWindow(ClockUtil.getCurrentTime(), commandContext)) {
                // reschedule after some delay
                Date nextRunDate = configuration.getNextRunWithDelay(ClockUtil.getCurrentTime());
                if (HistoryCleanupHelper.isWithinBatchWindow(nextRunDate, commandContext)) {
                    commandContext.getJobManager().reschedule(jobEntity, nextRunDate);
                    rescheduled = true;
                    incrementCountEmptyRuns(configuration, jobEntity);
                }
            }
        }
    }
    if (!rescheduled) {
        if (HistoryCleanupHelper.isBatchWindowConfigured(commandContext)) {
            rescheduleRegularCall(commandContext, jobEntity);
        } else {
            // nothing more to do, suspend the job
            suspendJob(jobEntity);
        }
        cancelCountEmptyRuns(configuration, jobEntity);
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Date(java.util.Date)

Example 45 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class ConcurrentJobExecutorTest method testCompetingJobExecutionFoxRetryStrategy.

@Test
@Deployment
public void testCompetingJobExecutionFoxRetryStrategy() {
    // given an MI subprocess with two instances
    runtimeService.startProcessInstanceByKey("miParallelSubprocess");
    List<Job> currentJobs = managementService.createJobQuery().list();
    assertEquals(2, currentJobs.size());
    // when the jobs are executed in parallel
    JobExecutionThread threadOne = new JobExecutionThread(currentJobs.get(0).getId());
    threadOne.startAndWaitUntilControlIsReturned();
    JobExecutionThread threadTwo = new JobExecutionThread(currentJobs.get(1).getId());
    threadTwo.startAndWaitUntilControlIsReturned();
    // then the first committing thread succeeds
    LOG.debug("test thread notifies thread 1");
    threadOne.proceedAndWaitTillDone();
    assertNull(threadOne.exception);
    // then the second committing thread fails with an OptimisticLockingException
    // and the job retries have not been decremented
    LOG.debug("test thread notifies thread 2");
    threadTwo.proceedAndWaitTillDone();
    assertNotNull(threadTwo.exception);
    Job remainingJob = managementService.createJobQuery().singleResult();
    // retries are configured as R5/PT5M, so no decrement means 5 retries left
    assertEquals(5, remainingJob.getRetries());
    assertNotNull(remainingJob.getExceptionMessage());
    JobEntity jobEntity = (JobEntity) remainingJob;
    assertNull(jobEntity.getLockOwner());
    // and there is a custom lock expiration time
    assertNotNull(jobEntity.getLockExpirationTime());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)68 Test (org.junit.Test)26 Date (java.util.Date)18 Job (org.camunda.bpm.engine.runtime.Job)13 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)11 HistoryCleanupJobHandlerConfiguration (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 SimpleDateFormat (java.text.SimpleDateFormat)6 List (java.util.List)6 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)6 Page (org.camunda.bpm.engine.impl.Page)5 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)4 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3