Shreyas arya

Generation

generate functionThu, 09 Feb 2023

When requests to Step Function fail, Workflow Service performs exponential backoff retries to notify Step Function service. Number of retries = 3 The total duration of all attempts doesn't exceed 10 seconds, the processing must not exceed the message visibility timeout.

public class ExponentialRetry { public static void main(String[] args) { int maxAttempts = 3; int delay = 1000; int maxDelay = 5000; int backoff = 2; int retries = 0; while(retries++ < maxAttempts) { try { // call aws step functions } catch(Exception ex) { // backoff exponential with jitter delay = getExponentialWithJitterDelay(delay, maxDelay, backoff); try { Thread.sleep(delay); } catch (Exception e) { // do nothing } } } } private static int getExponentialWithJitterDelay(int delay, int maxDelay, int backoff) { if (delay > maxDelay) { return maxDelay; } Random r = new Random(); double rand = (1 + r.nextDouble()) / 2; return (int) (rand * delay * backoff);

Questions about programming?Chat with your personal AI assistant