External task selection is random?

Hello,

I’m new to Camunda and BPMN in general and I have one question about External Taks. Right now I’ve got a few external tasks with the same topic-name, for these external tasks I have to call a REST service and based on the response I have to complete the task or leave it uncompleted. My worker fetchs and locks 1 task every 7 minutes (using cron and Spring boot). My question is, when I do fetchAndLock, the selected task is random? In that case for example the fetch and lock request could try to complete the same task 20 times, and the other tasks remain blocked meanwhile, how can I avoid that?

-Alex

assuming you’re not using priority then it’s more so unpredictable than it is random.

I can’t see this happening. Fetch and Lock would only return unlocked tasks. Can you explain under what circumstances you would expect to see blocking?

Assuming for example I have 20 external tasks on the same topic:

  • My worker fetch and lock one of the external tasks, it checks the service and the task shouldn’t be completed yet, then after the lock duration the task is unlocked without completion.
  • Then my worker fetchs and lock again another task and imagine (because you said the task selection is unpredictable) you lock again the same previous task, again it remains without completion…
  • There is a small chance (increased with the number of external tasks) that some task are never fetched and locked so they will never complete.

Am I right?

I think you are right.

Hi @Crw_alex94,

maybe it’s a better approach not just unlock the tasks but mark them as failed with a retry set to 1 and some interval.

Then this task will not be fetched until the retry interval is passed and you can work on other tasks.

Or you can decrease the priority of the task before you unlock it. And use priority for sorting.

Hope this helps, Ingo

2 Likes

Ingo is correct - there’s a lot more you can do doing including adding a retry cycle which would ensure that it wouldn’t be picked up immediately.