public static async Task RetryAsync()

in Common/RetryHelper.cs [21:80]


        public static async Task<T> RetryAsync<T>(Func<Task<T>> function, Func<Guid, Exception, Task<Exception>> exceptionHandler, int retryCount, int secsDelay = 1)
        {
            Guid requestId = Guid.NewGuid();
            Exception exception = null;
            bool succeeded = true;
            for (int i = 0; i < retryCount; i++)
            {
                try
                {
                    succeeded = true;
                    return await function();
                }
                catch (Exception ex)
                {
                    exception = TranslateException(requestId, ex);

                    if (exceptionHandler != null)
                    {
                        try
                        {
                            exception = await exceptionHandler(requestId, exception);
                        }
                        catch
                        {
                            // continue with the original exception handling process
                        }
                    }

                    if (exception is RetryPermanentException)
                    {
                        //exit the for loop as we are not retrying for anything considered permanent
                        break;
                    }

                    succeeded = false;
                    Logger.LogTrace(LogDestination.File, $"Sleeping for {secsDelay} seconds and retrying {requestId} again.");

                    await Task.Delay(secsDelay * 1000);
                    
                    // add 1 second to delay so that each delay is slightly incrementing in wait time
                    secsDelay += 1;
                }
                finally
                {
                    if (succeeded && i >= 1)
                    {
                        Logger.LogSuccess(LogDestination.File, $"request {requestId} succeeded.");
                    }
                }
            }

            if (exception is null)
            {
                throw new RetryExhaustedException($"Retry count exhausted for {requestId}.");
            }
            else
            {
                throw exception;
            }
        }