Hi all,
I’m figuring out how to use the externalWorkers in my business case.
If an external worker did complete its task but couldn’t call ‘complete’ on the Engine (perhaps because this wasn’t temporarily reachable), the task will be executed more times…won’t it?
Are there patterns to avoid such issues?
Thank you!
Bye
Fabio
Hi @Fabio_Salvi!
Yes, as you predicted (and as described here in the docs), there is a configurable timeout when you fetch and lock a group of external tasks to be executed. Once a task has been fetched and locked, and that period of time expires, the task will be available for fetching again unless you are unable to extend the lock (presumably if you can’t complete the task, you probably cannot extend the lock in this scenario). This allows tasks that cannot be completed, failed, extended, or incident created (for whatever reason) to not be completely abandoned by the system.
As far as patterns go to avoid such an issue, like everything, that depends on the nature of work you’re externalizing and the system(s) it interfaces with. It is probably best to understand the fetch and lock pattern going into your design so that you can define an approach that is robust enough to handle such a situation. In that same line of thinking, the external task pattern also allows for incident handling that provides the ability to retry tasks as well (so timeout is not your only “double work” type scenario).
Best of luck! 
Hi @Fabio_Salvi,
here you are touching the ground of decoupled services which is common for microservices architectures. The only option not to harm your called business service from multiple calls from the external task workers is to create the business service to be idempotent.
With a given transaction id as a parameter for a call to charge the credit card, the charging service can check if the money was already deducted before (and return with OK) or not. This avoids deducting the money multiple times for the same transaction.
Now you create the transaction in the process before you enter the service with the external task topic. The worker completes the call to the charge credit card service sucessfully but fails to complete the task (because of network problems or whatever). If the next worker picks up the task with the same transaction, the credit card service is able to avoid to charge the card again.
Hope this helps, Ingo
1 Like