Good afternoon, I am trying to find out a way to deal with what we can call “non-critical” errors.
In this example:
We have 3 tasks that run in parallel, I want it so that if task 2 throws an error for whatever reason, the other 2 still complete and the workflow signals as completed instead of failed.
I know I can do a try, catch inside each activity and if they error just handle it within the activity possibly return an object that contains an error property, I just wonder if this is the best way to handle this or if there is a “best practice” around situations such as these?
Yes, you can convert an error in the activity into a normal return value.
Something to consider is whether there are any failures that you might want to retry.
For example, if you’re making an API call to a service that’s briefly down you might want to retry; if you get an “invalid password” response to an authentication call there might not be any point in retrying that one.
Conveniently Temporal offers activity retry policies so you can specify if you want an activity to be retried, and, if so, how frequently and for how long… without needing to record each individual retry in the workflow execution history.
You can specify particular errors that shouldn’t be retried, but, if your activity can have a normal and expected error that shouldn’t be retried, as you say you can also catch that error in the activity and return a normal value.