Hi, I am struggling with Multi-instance External Tasks. I created a simplest bpmn to show the problem.
The Task is External, Loop Cardinality is fixed number (e.g. 100), and has
-
Multi Instance Async Before - true
-
Multi Instance Async After - true
-
Multi Instance Exclusive - true
-
Async Before - true
-
Async After - true
-
Exclusive - true
Then I have a External Task Poller, which is for sake of simplicity polling tasks synchronously in a for loop, logging and completing.
@Scheduled(
fixedDelayString = "${externaltask.worker.poll.rate}"
)
public void poll() {
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(10, externalTaskConfiguration.getWorkerId())
.topic(topic.getName(), externalTaskConfiguration.getDefaultLockDuration())
.execute();
tasks.forEach(task -> {
try {
log.info("-----------------------------------Executing task: {}", task.getId());
} catch (Exception e) {
log.error("failed to process external task - {}", task.getId(), e);
}
externalTaskService.complete(task.getId(), task.getWorkerId(), task.getVariables());
System.out.println("------------------------------------------------completed: " + task.getId());
}
);
}
I am getting following exception
org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'UPDATE VariableInstanceEntity[99e059c5-26a0-11e8-b347-aa5d7001bc63]' failed. Entity was updated by another transaction concurrently.
at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.concurrentUpdateDbEntityException(EnginePersistenceLogger.java:130)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.handleOptimisticLockingException(DbEntityManager.java:406)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.checkFlushResults(DbEntityManager.java:365)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:345)
In Camunda Cockpit I can see that nrOfActiveInstances are not 0 after quite long time, even though all tasks were polled and completed.
- nrOfInstances - 100
- nrOfCompletedInstances - 64
- nrOfActiveInstances - 36
And the process would stuck in this state forever…
I have also tried handleFailure method in ExternalTaskService, the situation didn’t chnage much.
Any help, hint, suggestion will be much appreciated. Thanks in advance.