we have a requirement where a workflow is executed with a number of activities in it. One of those activities is to call an API and get the response back from it.
If the response is positive (let’s say an OK is returned), we can continue the flow. If a KO is received, we want to wait for 24 hours and then re-execute the same activity. Now the time it takes to get back an OK can be pretty long…We are talking about days, weeks potentially even months.
What is the best approach to execute something like this? Should we call the API, get the response and based on that, throw a Retryable exception? And then we can play around with the retry policy or is there a better way of doing this?
You can use activity retries to approach your “polling” use case. So for this activity could set in its retry policy
BackoffCoefficient to 1 and
InitialInterval to the interval you want to “poll”, invoking this api again to get result. So lets say that you want to retry this activity every minute then would set InitialInterval to 60s.
From activity code then if you get a “OK” you can complete this activity, if you get a “KO” then return/throw a retryable application failure which would then schedule next activity retry based on your retry policy.
This has the benefit that individual retries are not recorded in event history so you would not have to worry about exceeded event history count and dealing with continueasnew. The con is that you cannot change the poll interval once it is set on initial activity options.
To cancel your “poll” after some time you could set a ScheduleToClose timeout to max amount of time you the poll to last, at that point can handle activity timeout and invoke it again if needed later on.
Thanks for this solution! That helps.