External Task Client: Extend Lock(extendLock(ExternalTask,NewDuration)) releasing lock after new duration

Hello

We are facing issue while extending lock duration for the external task client.
We have external task client which listens to 3 topics. 3 pods are running in dev environment. Below is how we are trying to extend lock.
Our implementation is using:
camunda-bpm-spring-boot-starter-webapp:7.20
camunda-bpm-spring-boot-starter-rest:7.20
spring-boot:3.3

asyncTimeout: 6000
lockDuration: 180000
extendLockDuration:240000

try{
createHandler();
extendLock;
----businessLogic----;
completeTask;
}
catch{

}

Observation:

  1. Lock Duration is set once the client is built, and extend lock is called before the business logic is processed. ExtendLock replaces the lock duration when it is called, so the task gets locked for 240000milisec by Worker1.
    Once 240000milisec is over, it is releasing the lock and the task is locked for another 240000milisec by Worker2.

  2. As there are 3 workers(3 pods) it is continuously releasing and locked by different worker. The task never gets completed.

We have tried having lockDuration : 3min and extendLock:10sec, in this scenario, the task was getting locked for 10sec and released every 10sec.

Questions:

  1. Is there a different way extend lock should be invoked?Do we need a condition to check if the task has needs more than the lockduration then extend the lock.

  2. How do we write a listener that can keep checking if worker needs more time to finish a task?

  3. Is there a discussion thread we can refer to for a Java based external task implementation that uses extendLock?

@Ingo_Richtsmeier @Niall @hassang @jonathan.lukas

Hello @payelpaul036 ,

in general, the lock can be extended at any time.

If you need to extend the lock for a long-running task, I would recommend you to:

  • delegate the execution of the task to a future
  • have another thread active to check the future and extend the lock duration from time to time

I hope this helps

Jonathan

Hello @jonathan.lukas ,

Thank you for taking time to respond to my post.

Is there a code that I can look in to?

I followed the below code:
https://github.com/camunda-consulting/camunda-7-code-examples/blob/600a035e69b938f7896c1d6fc964625dbde94be6/snippets/async-external-task-spring-boot/src/main/java/com/camunda/consulting/AsyncRestCallHandler.java

I tried extending on Timeoutexception, but it throws exception saying “Could not extend lock as the lock has expired.”

If there is a working example I can refer, it will help as our code is in Production and we have set a lockduration to 4min for now, so that nothing fails with locking exception. We want to use the extendLock feature to change the lock duration when ever necessary,

Thank you again. Your response is helpful.

Payel

Hello @payelpaul036 ,

I do not have an example at hand, but the moment when the timeout exception occurs is already too late.

In pseudo code, the extend timeout call would be controlled like this:

function handle(externalTask, externalTaskService) {
  // this will repeatidly schedule a call to extend the timeout some seconds BEFORE it actually happens
  startExtendTimeoutScheduling(externalTask, externalTaskService);
  // this is the actual business logic
  doStuff();
  // simple complete to keep the snippet kiss
  externalTaskService.complete(externalTask);
  // as soon as the task is complete, we can stop extending its timeout
  stopExtendTimeoutScheduling(externalTask, externalTaskService);
}

I hope this helps

Jonathan