Is it possible to specify number of retries based on the exception?

For example, say we have to ways activity can fail:

  • server error (e.g. 500)
  • api timeout (due to increased load)

Consider following scenario:

  1. First activity is started (schedule-to-close: 30s)
  2. It sends http request, and it fails after 10 seconds (timeout)
  3. During this time the upstream server is still processing the request
  4. Activity is rescheduled (remaining time is 20s)
  5. It sends a new http request, and it just happens to compete with previous and fails with 500 (due to already modified resource)
  6. Activity is expected to re-schedule (If we receive 500, we’d not want to retry it more than once)
  7. It is executed, and sending the request this time results in 200, since idempotence guard worked out.

When we receive timeout, we use backoff to delay new request.
Yet, on the other hand, if we receive 500 every time, we’d not want it to repeat indefinitely.
We’d want to try only once and then stop.

Is it acoomplishable only via custom code (ApplicationFailure), or what is the recommended way to do this?

You can implement this using ApplicationError non_retryable and next_retry_delay arguments.

1 Like