Customizing retry frequency of transaction
I want to customized retry frequency of transaction so that 503 error can be prevented while pushing FHIR bundle to the LFS.
How do I achieve this?
Reference the following algorithm to increase the retry interval of IRIS transaction
An exponential backoff algorithm retries requests exponentially, increasing the waiting time between retries up to a maximum backoff time. The following algorithm implements truncated exponential backoff with jitter:
- Send a request to the Cloud Healthcare API.
- If the request fails, wait 1 +
random-fractionseconds, then retry the request. - If the request fails, wait 2 +
random-fractionseconds, then retry the request. - If the request fails, wait 4 +
random-fractionseconds, then retry the request. - Continue this pattern, waiting 2n +
random-fractionseconds after each retry, up to amaximum-backofftime. - After
deadlineseconds, stop retrying the request.
Use the following values as you implement the algorithm:
- Before each retry, the wait time is
min((2n + random-fraction), maximum-backoff), withnstarting at 0 and incremented by 1 for each retry. - Replace
random-fractionwith a random fractional value less than or equal to 1. Use a different value for each retry. Adding this random value prevents clients from becoming synchronized and sending many retries at the same time. - Replace
maximum-backoffwith the maximum amount of time, in seconds, to wait between retries. Typical values are 32 or 64 (25 or 26) seconds. Choose the value that works best for your use case. - Replace
deadlinewith the maximum number of seconds to keep sending retries. Choose a value that reflects your use case.
The client can retry after reaching the maximum-backoff time using the same value as the backoff. For example, if the maximum-backoff time is 64 seconds, retry every 64 seconds. Ensure that the client doesn't retry indefinitely.
Comments
What do you refer to with "frequency of transaction"?
Are you using a Business Process with an adapter?
Usually transactios refer to database operations (like data insert, update).
If I were to write this in an operation using the EnsLib.HTTP.OutboundAdapter, my approach would be something similar to:
Set tSC = ..Adapter.SendFormData(.webresponse,"GET",webrequest)
//begin backoff algorithm//Get start time in secondsSet startInSeconds = $ZDTH($H,-2)
//Set initial params for algorithmSet wait = 1, maximumBackoff=64, deadline=300//Only run while Status Code is 504While (webresponse.StatusCode = "504"){
//HANG for x.xx secondsHANG wait_"."_$RANDOM(9)_$RANDOM(9)
//Call endpointSet tSC = ..Adapter.SendFormData(.webresponse,"GET",webrequest)
//Increment potential wait periodsIf wait < maximumBackoff Set wait = wait*2//Adjust wait if previous action takes us above the maximum backoffIf wait > maximumBackoff Set wait = maximumBackoff
//Check if deadline has been hit, exiting the While loop if we haveSet currentTimeInSeconds = $ZDTH($H,-2)
If (currentTimeInSeconds-startInSeconds>=deadline){Quit}
}This is untested however, so massive pinch of salt is required 😅