コード例 #1
0
        private static void SafeExecuteSync(BatchRequest batchRequest, int attemptOrderNumber)
        {
            // Attempt to execute provided request.
            try { Task.Run(async() => { await batchRequest.ExecuteAsync(); }).Wait(); }

            // On request operation canceled
            catch (OperationCanceledException ex)
            {
                // Increase attempt order number by one.
                attemptOrderNumber++;

                // Validate whether request reattempt limit hasn't been exceeded
                if (RequestsExecutor._cancellationErrorAttemptsLimit < attemptOrderNumber)
                {
                    // ... and throw appropriate exception if has. attempt
                    throw new BatchRequestExecutionUnexpectedException(batchRequest, ex);
                }

                // Await appropriate cooldown period.
                Thread.Sleep(RequestsExecutor._cancellationErrorCooldown);

                // Reattempt.
                RequestsExecutor.SafeExecuteSync(batchRequest, attemptOrderNumber);
            }

            // On google internal error encounter, retry
            catch (Google.GoogleApiException ex) when(ex.Message.Contains("Internal error encountered. [500]"))
            {
                // Increase attempt order number by one.
                attemptOrderNumber++;

                // Validate whether request reattempt limit hasn't been exceeded
                if (RequestsExecutor._internalErrorAttemptsLimit < attemptOrderNumber)
                {
                    // ... and throw appropriate exception if has. attempt
                    throw new BatchRequestExecutionUnexpectedException(batchRequest, ex);
                }

                // Await appropriate cooldown period.
                Thread.Sleep(RequestsExecutor._internalErrorCooldown);

                // Reattempt.
                RequestsExecutor.SafeExecuteSync(batchRequest, attemptOrderNumber);
            }

            // On used all available requests quota
            catch (Google.GoogleApiException ex) when(ex.Message.Contains("Quota exceeded for quota group"))
            {
                // Set session request limiter state to indicate no available google requests quota at this time.
                SessionRequestsLimiter.Instance.ClearAvailableQuota();

                // Reattempt.
                RequestsExecutor.SafeExecuteSync(batchRequest, attemptOrderNumber);
            }

            // On any other unexpected database error
            catch (Google.GoogleApiException ex) { throw new BatchRequestExecutionUnexpectedException(batchRequest, ex); }
        }
コード例 #2
0
        private static async Task <TResponse> SafeExecuteAsync <TResponse>(IClientServiceRequest <TResponse> request, int attemptOrderNumber)
        {
            // Attempt to execute provided request.
            try { return(await request.ExecuteAsync()); }

            // On request operation canceled
            catch (OperationCanceledException ex)
            {
                // Increase attempt order number by one.
                attemptOrderNumber++;

                // Validate whether request reattempt limit hasn't been exceeded
                if (RequestsExecutor._cancellationErrorAttemptsLimit < attemptOrderNumber)
                {
                    // ... and throw appropriate exception if has. attempt
                    throw new RequestExecutionUnexpectedException(request, ex);
                }

                // Await appropriate cooldown period.
                await Task.Delay(RequestsExecutor._cancellationErrorCooldown);

                // Reattempt.
                return(await RequestsExecutor.SafeExecuteAsync(request, attemptOrderNumber));
            }

            // On google internal error encounter, retry
            catch (Google.GoogleApiException ex) when(ex.Message.Contains("Internal error encountered. [500]"))
            {
                // Increase attempt order number by one.
                attemptOrderNumber++;

                // Validate whether request reattempt limit hasn't been exceeded
                if (RequestsExecutor._internalErrorAttemptsLimit < attemptOrderNumber)
                {
                    // ... and throw appropriate exception if has. attempt
                    throw new RequestExecutionUnexpectedException(request, ex);
                }

                // Await appropriate cooldown period.
                await Task.Delay(RequestsExecutor._internalErrorCooldown);

                // Reattempt.
                return(await RequestsExecutor.SafeExecuteAsync <TResponse>(request, attemptOrderNumber));
            }

            // On used all available requests quota
            catch (Google.GoogleApiException ex) when(ex.Message.Contains("Quota exceeded for quota group"))
            {
                // Set session request limiter state to indicate no available google requests quota at this time.
                SessionRequestsLimiter.Instance.ClearAvailableQuota();

                // Reattempt.
                return(await RequestsExecutor.SafeExecuteAsync <TResponse>(request, attemptOrderNumber));
            }

            // On any other unexpected database error
            catch (Google.GoogleApiException ex) { throw new RequestExecutionUnexpectedException(request, ex); }
        }
コード例 #3
0
 public static async Task <TResponse> SafeExecuteAsync <TResponse>(IClientServiceRequest <TResponse> request)
 {
     return(await RequestsExecutor.SafeExecuteAsync <TResponse>(request, 0));
 }
コード例 #4
0
 public static TResponse SafeExecuteSync <TResponse>(IClientServiceRequest <TResponse> request)
 {
     return(RequestsExecutor.SafeExecuteSync <TResponse>(request, 0));
 }
コード例 #5
0
 public static async Task SafeExecuteAsync(BatchRequest batchRequest)
 {
     await RequestsExecutor.SafeExecuteAsync(batchRequest, 0);
 }
コード例 #6
0
 public static void SafeExecuteSync(BatchRequest batchRequest)
 {
     RequestsExecutor.SafeExecuteSync(batchRequest, 0);
 }