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