use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class TransitionInstanceJobHandler method handle.
@Override
public void handle(MigratingInstanceParseContext parseContext, MigratingTransitionInstance transitionInstance, List<JobEntity> elements) {
for (JobEntity job : elements) {
if (!isAsyncContinuation(job)) {
continue;
}
ScopeImpl targetScope = transitionInstance.getTargetScope();
if (targetScope != null) {
JobDefinitionEntity targetJobDefinitionEntity = parseContext.getTargetJobDefinition(transitionInstance.getTargetScope().getId(), job.getJobHandlerType());
MigratingAsyncJobInstance migratingJobInstance = new MigratingAsyncJobInstance(job, targetJobDefinitionEntity, transitionInstance.getTargetScope());
transitionInstance.setDependentJobInstance(migratingJobInstance);
parseContext.submit(migratingJobInstance);
}
parseContext.consume(job);
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class TransitionInstanceHandler method handle.
@Override
public void handle(MigratingInstanceParseContext parseContext, TransitionInstance transitionInstance) {
if (!isAsyncTransitionInstance(transitionInstance)) {
return;
}
MigrationInstruction applyingInstruction = parseContext.getInstructionFor(transitionInstance.getActivityId());
ScopeImpl sourceScope = parseContext.getSourceProcessDefinition().findActivity(transitionInstance.getActivityId());
ScopeImpl targetScope = null;
if (applyingInstruction != null) {
String activityId = applyingInstruction.getTargetActivityId();
targetScope = parseContext.getTargetProcessDefinition().findActivity(activityId);
}
ExecutionEntity asyncExecution = Context.getCommandContext().getExecutionManager().findExecutionById(transitionInstance.getExecutionId());
MigratingTransitionInstance migratingTransitionInstance = parseContext.getMigratingProcessInstance().addTransitionInstance(applyingInstruction, transitionInstance, sourceScope, targetScope, asyncExecution);
MigratingActivityInstance parentInstance = parseContext.getMigratingActivityInstanceById(transitionInstance.getParentActivityInstanceId());
migratingTransitionInstance.setParent(parentInstance);
List<JobEntity> jobs = asyncExecution.getJobs();
parseContext.handleDependentTransitionInstanceJobs(migratingTransitionInstance, jobs);
parseContext.handleDependentVariables(migratingTransitionInstance, collectTransitionInstanceVariables(migratingTransitionInstance));
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class TransitionInstanceHandler method isAsyncTransitionInstance.
/**
* Workaround for CAM-5609: In general, only async continuations should be represented as TransitionInstances, but
* due to this bug, completed multi-instances are represented like that as well. We tolerate the second case.
*/
protected boolean isAsyncTransitionInstance(TransitionInstance transitionInstance) {
String executionId = transitionInstance.getExecutionId();
ExecutionEntity execution = Context.getCommandContext().getExecutionManager().findExecutionById(executionId);
for (JobEntity job : execution.getJobs()) {
if (AsyncContinuationJobHandler.TYPE.equals(job.getJobHandlerType())) {
return true;
}
}
return false;
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class ManagementServiceTest method testSetJobRetriesUnlocksInconsistentJob.
public void testSetJobRetriesUnlocksInconsistentJob() {
// case 1
// given an inconsistent job that is never again picked up by a job executor
createJob(0, "owner", ClockUtil.getCurrentTime());
// when the job retries are reset
JobEntity job = (JobEntity) managementService.createJobQuery().singleResult();
managementService.setJobRetries(job.getId(), 3);
// then the job can be picked up again
job = (JobEntity) managementService.createJobQuery().singleResult();
assertNotNull(job);
assertNull(job.getLockOwner());
assertNull(job.getLockExpirationTime());
assertEquals(3, job.getRetries());
deleteJobAndIncidents(job);
// case 2
// given an inconsistent job that is never again picked up by a job executor
createJob(2, "owner", null);
// when the job retries are reset
job = (JobEntity) managementService.createJobQuery().singleResult();
managementService.setJobRetries(job.getId(), 3);
// then the job can be picked up again
job = (JobEntity) managementService.createJobQuery().singleResult();
assertNotNull(job);
assertNull(job.getLockOwner());
assertNull(job.getLockExpirationTime());
assertEquals(3, job.getRetries());
deleteJobAndIncidents(job);
// case 3
// given a consistent job
createJob(2, "owner", ClockUtil.getCurrentTime());
// when the job retries are reset
job = (JobEntity) managementService.createJobQuery().singleResult();
managementService.setJobRetries(job.getId(), 3);
// then the lock owner and expiration should not change
job = (JobEntity) managementService.createJobQuery().singleResult();
assertNotNull(job);
assertNotNull(job.getLockOwner());
assertNotNull(job.getLockExpirationTime());
assertEquals(3, job.getRetries());
deleteJobAndIncidents(job);
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class ManagementServiceTest method testSetJobRetriesByDefinitionUnlocksInconsistentJobs.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testSetJobRetriesByDefinitionUnlocksInconsistentJobs() {
// given a job definition
final JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
// and an inconsistent job that is never again picked up by a job executor
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
JobManager jobManager = commandContext.getJobManager();
MessageEntity job = new MessageEntity();
job.setJobDefinitionId(jobDefinition.getId());
job.setJobHandlerType("any");
job.setLockOwner("owner");
job.setLockExpirationTime(ClockUtil.getCurrentTime());
job.setRetries(0);
jobManager.send(job);
return null;
}
});
// when the job retries are reset
managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 3);
// then the job can be picked up again
JobEntity job = (JobEntity) managementService.createJobQuery().singleResult();
assertNotNull(job);
assertNull(job.getLockOwner());
assertNull(job.getLockExpirationTime());
assertEquals(3, job.getRetries());
deleteJobAndIncidents(job);
}
Aggregations