private async Task <AnnotationResultSummary> InvokeAndRetryWhenThrottled(string functionArn, string functionInput) { AnnotationResultSummary resultSummary; while (true) { try { var invokeRequest = new InvokeRequest { FunctionName = functionArn, Payload = functionInput, InvocationType = "RequestResponse" }; var payload = GetAnnotationResult(invokeRequest); resultSummary = GetResultSummaryFromSuccessInvocation(payload); break; } catch (Exception e) when(ExceptionUtilities.HasException <TooManyRequestsException>(e)) { Logger.WriteLine($"Job {_jobIndex}: Invocation is throttled. Retry in {WaitBeforeRetry} ms."); _numRetries++; await Task.Delay(WaitBeforeRetry); } catch (Exception e) when(e.HasErrorMessage(UnknownErrorMessage)) { Logger.WriteLine($"Job {_jobIndex}: {UnknownErrorMessage}. Retry in {WaitBeforeRetry} ms."); _numRetries++; await Task.Delay(WaitBeforeRetry); } } return(resultSummary); }
internal AnnotationResultSummary GetResultSummaryFromFailedInvocation(Exception e) { var additionalDescription = ""; if (ExceptionUtilities.HasException <TaskCanceledException>(e)) { _errorCategory = ErrorCategory.TimeOutError; additionalDescription = $" Annotation job was not finished in {_annotationTimeOut} milliseconds."; } if (_errorCategory == null) { _errorCategory = ExceptionUtilities.ExceptionToErrorCategory(e); } e = ExceptionUtilities.GetInnermostException(e); string errorMessage = $"Failed job when invoking the annotation job: {e.Message}.{additionalDescription}"; return(AnnotationResultSummary.Create(null, _errorCategory, errorMessage)); }