use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class FoxJobRetryCmdTest method assertJobRetriesForActivity.
protected void assertJobRetriesForActivity(ProcessInstance pi, String activityId) {
assertNotNull(pi);
waitForExecutedJobWithRetriesLeft(4);
stillOneJobWithExceptionAndRetriesLeft();
Job job = fetchJob(pi.getProcessInstanceId());
assertNotNull(job);
assertEquals(pi.getProcessInstanceId(), job.getProcessInstanceId());
assertEquals(4, job.getRetries());
ExecutionEntity execution = fetchExecutionEntity(pi.getProcessInstanceId(), activityId);
assertNotNull(execution);
waitForExecutedJobWithRetriesLeft(3);
job = refreshJob(job.getId());
assertEquals(3, job.getRetries());
stillOneJobWithExceptionAndRetriesLeft();
execution = refreshExecutionEntity(execution.getId());
assertEquals(activityId, execution.getActivityId());
waitForExecutedJobWithRetriesLeft(2);
job = refreshJob(job.getId());
assertEquals(2, job.getRetries());
stillOneJobWithExceptionAndRetriesLeft();
execution = refreshExecutionEntity(execution.getId());
assertEquals(activityId, execution.getActivityId());
waitForExecutedJobWithRetriesLeft(1);
job = refreshJob(job.getId());
assertEquals(1, job.getRetries());
stillOneJobWithExceptionAndRetriesLeft();
execution = refreshExecutionEntity(execution.getId());
assertEquals(activityId, execution.getActivityId());
waitForExecutedJobWithRetriesLeft(0);
job = refreshJob(job.getId());
assertEquals(0, job.getRetries());
assertEquals(1, managementService.createJobQuery().withException().count());
assertEquals(0, managementService.createJobQuery().withRetriesLeft().count());
assertEquals(1, managementService.createJobQuery().noRetriesLeft().count());
execution = refreshExecutionEntity(execution.getId());
assertEquals(activityId, execution.getActivityId());
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class JobDeclaration method createJobInstance.
// Job instance factory //////////////////////////////////////////
/**
* @return the created Job instances
*/
public T createJobInstance(S context) {
T job = newJobInstance(context);
// set job definition id
String jobDefinitionId = resolveJobDefinitionId(context);
job.setJobDefinitionId(jobDefinitionId);
if (jobDefinitionId != null) {
JobDefinitionEntity jobDefinition = Context.getCommandContext().getJobDefinitionManager().findById(jobDefinitionId);
if (jobDefinition != null) {
// if job definition is suspended while creating a job instance,
// suspend the job instance right away:
job.setSuspensionState(jobDefinition.getSuspensionState());
job.setProcessDefinitionKey(jobDefinition.getProcessDefinitionKey());
job.setProcessDefinitionId(jobDefinition.getProcessDefinitionId());
job.setTenantId(jobDefinition.getTenantId());
}
}
job.setJobHandlerConfiguration(resolveJobHandlerConfiguration(context));
job.setJobHandlerType(resolveJobHandlerType(context));
job.setExclusive(resolveExclusive(context));
job.setRetries(resolveRetries(context));
job.setDuedate(resolveDueDate(context));
// contentExecution can be null in case of a timer start event or
// and batch jobs unrelated to executions
ExecutionEntity contextExecution = resolveExecution(context);
if (Context.getProcessEngineConfiguration().isProducePrioritizedJobs()) {
long priority = Context.getProcessEngineConfiguration().getJobPriorityProvider().determinePriority(contextExecution, this, jobDefinitionId);
job.setPriority(priority);
}
if (contextExecution != null) {
// in case of shared process definitions, the job definitions have no tenant id.
// To distinguish jobs between tenants and enable the tenant check for the job executor,
// use the tenant id from the execution.
job.setTenantId(contextExecution.getTenantId());
}
postInitialize(context, job);
return job;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class MigratingTransitionInstance method detachState.
@Override
public void detachState() {
jobInstance.detachState();
for (MigratingInstance dependentInstance : migratingDependentInstances) {
dependentInstance.detachState();
}
ExecutionEntity execution = resolveRepresentativeExecution();
execution.setActive(false);
getParent().destroyAttachableExecution(execution);
setParent(null);
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class ActivityInstanceHandler method handle.
@Override
public void handle(MigratingInstanceParseContext parseContext, ActivityInstance element) {
MigratingActivityInstance migratingInstance = null;
MigrationInstruction applyingInstruction = parseContext.getInstructionFor(element.getActivityId());
ScopeImpl sourceScope = null;
ScopeImpl targetScope = null;
ExecutionEntity representativeExecution = parseContext.getMapping().getExecution(element);
if (element.getId().equals(element.getProcessInstanceId())) {
sourceScope = parseContext.getSourceProcessDefinition();
targetScope = parseContext.getTargetProcessDefinition();
} else {
sourceScope = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());
if (applyingInstruction != null) {
String activityId = applyingInstruction.getTargetActivityId();
targetScope = parseContext.getTargetProcessDefinition().findActivity(activityId);
}
}
migratingInstance = parseContext.getMigratingProcessInstance().addActivityInstance(applyingInstruction, element, sourceScope, targetScope, representativeExecution);
MigratingActivityInstance parentInstance = parseContext.getMigratingActivityInstanceById(element.getParentActivityInstanceId());
if (parentInstance != null) {
migratingInstance.setParent(parentInstance);
}
CoreActivityBehavior<?> sourceActivityBehavior = sourceScope.getActivityBehavior();
if (sourceActivityBehavior instanceof MigrationObserverBehavior) {
((MigrationObserverBehavior) sourceActivityBehavior).onParseMigratingInstance(parseContext, migratingInstance);
}
parseContext.submit(migratingInstance);
parseTransitionInstances(parseContext, migratingInstance);
parseDependentInstances(parseContext, migratingInstance);
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class CompensationInstanceHandler method createMigratingEventScopeInstance.
protected MigratingProcessElementInstance createMigratingEventScopeInstance(MigratingInstanceParseContext parseContext, EventSubscriptionEntity element) {
ActivityImpl compensatingActivity = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());
MigrationInstruction migrationInstruction = getMigrationInstruction(parseContext, compensatingActivity);
ActivityImpl eventSubscriptionTargetScope = null;
if (migrationInstruction != null) {
if (compensatingActivity.isCompensationHandler()) {
ActivityImpl targetEventScope = (ActivityImpl) parseContext.getTargetActivity(migrationInstruction).getEventScope();
eventSubscriptionTargetScope = targetEventScope.findCompensationHandler();
} else {
eventSubscriptionTargetScope = parseContext.getTargetActivity(migrationInstruction);
}
}
ExecutionEntity eventScopeExecution = CompensationUtil.getCompensatingExecution(element);
MigrationInstruction eventScopeInstruction = parseContext.findSingleMigrationInstruction(eventScopeExecution.getActivityId());
ActivityImpl targetScope = parseContext.getTargetActivity(eventScopeInstruction);
MigratingEventScopeInstance migratingCompensationInstance = parseContext.getMigratingProcessInstance().addEventScopeInstance(eventScopeInstruction, eventScopeExecution, eventScopeExecution.getActivity(), targetScope, migrationInstruction, element, compensatingActivity, eventSubscriptionTargetScope);
parseContext.consume(element);
parseContext.submit(migratingCompensationInstance);
parseDependentEntities(parseContext, migratingCompensationInstance);
return migratingCompensationInstance;
}
Aggregations