External Task - continuously keeps running if not completed

Hi

I have an external task and a client that runs it as below:
Instead of completing the task there itself, i need another process to complete this task. That’s why i commented out the complete statement.
The problem is , the stuff inside keeps repeating .
// subscribe to the ingestion topic
client.subscribe(“ingestion”).lockDuration(10000).handler((externalTask, externalTaskService) -> {

		/* some work  */

System.out.println(“printing from my external task—”);
System.out.println(“The External Task Ingestion” + externalTask.getId() + " waiting to be completed!");

		}).open();

Please let me know if someone has an idea why this happens.

Thanks
Urvashi

It looks like you are locking the task for 10 seconds, but since you are not completing it, the client will keep picking up the same task as it had before, since the lock expires without completion. The idea of using the external task pattern is that you lock the task, perform it and report back by completing it (in the happy-flow case).

Hi. Thanks for the response.
I understood what you are saying.
My requirement is , I am sending files to a server and waiting for a response using a rest api. I want the external task completion to be done by the rest api, not by the client.

Can you please suggest a way to accomplish this?

Thanks
Urvashi

I haven’t used it that way personally, but the documentation on completing the task, which is possible using the REST API can be found here: Complete External Task | docs.camunda.org

Note the remark there:

workerId The id of the worker that completes the task. Must match the id of the worker who has most recently locked the task.

So you need to make sure that the client that invokes the REST API to complete the task provides the same workerId as the external task client. This is because if one worker locks a task, another one cannot complete it.

Also, make sure you lock the task for long enough so there is time for the full processing to be done and then the completion to be done using the REST API. This will prevent the same task from being picked up. This is specified with the .lockDuration() method in your client setup. Alternatively, if there’s no reliable prediction on how much time might be needed, you can extend the lock while processing which is documented here: External Task Client | docs.camunda.org

Thanks. I fixed this by increasing the lock duration to 1000000. Increasing to an extremely large value does fix my problem of multiple execution.
However, are there any drawbacks of a large lock duration?

Not on the processing side. Seen from the process, an extremely long lock has the effect, that even though the worker may have stopped processing due to an error, the lock cannot be released for a long time. So process execution is blocked.

For those cases where you don’t want to lock extremely long but might need a long time to process in total, it’s an option to continuously extend the lock duration from the worker. That way if the worker quits, the lock will still expire relatively quickly so it can be picked up by another worker.