Activity retries without exception

  1. How can I configure my activity to retry when there is no failure ? Eg. I want to retry until status field in response is ‘xyz’.

You fail the activity by throwing an exception (in Java SDK at least) to force a retry. You specify which failures are not retryable by adding them ActivityOptions.RetryOptions.DoNotRetry. Another option is to throw a non retryable application failure created through ApplicationFailure.newNonRetryableFailure.

  1. Should I model this in a way such that both polling and persisting the response is part of same activity OR should i ideally create multiple activities - one for polling and other for persisting the response ?

I would model it as two separate activities unless the payload is large. The main reason that these activities might have different timeouts and retry options.

  1. Can I use workflow sleep to retry and practically just use activities for polling response and persisting in db ?

You can, but it is not recommended. The reason is that each retry is going to add events to the workflow history and it can get too large pretty fast. The built in service side retries to not add events to the history on retries. There are cases when you want to retry sequences of activities, then in this case using workflow side retries is reasonable.

This post has some additional ideas for polling.