public async Task <IBlob> GetAsync(string key) { int retryCount = 0; Exception lastException; do { if (retryCount > 0) { await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); } try { var request = new GetObjectRequest( host: client.Host, bucketName: bucketName, key: key ); return(await client.GetObjectAsync(request).ConfigureAwait(false)); } catch (S3Exception ex) when(ex.IsTransient) { lastException = ex; } retryCount++; }while (retryPolicy.ShouldRetry(retryCount)); throw lastException; }
public async Task <UpdateItemResult> UpdateItemUsingRetryPolicyAsync(UpdateItemRequest request, RetryPolicy retryPolicy) { var retryCount = 0; Exception lastException; do { if (retryCount > 0) { await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); } try { return(await UpdateItemAsync(request).ConfigureAwait(false)); } catch (DynamoDbException ex) when(ex.IsTransient) { lastException = ex; } retryCount++; } while (retryPolicy.ShouldRetry(retryCount)); throw lastException; }
public async Task <QueryResult> QueryAsync(DynamoQuery query, RetryPolicy retryPolicy) { var retryCount = 0; Exception lastException; do { if (retryCount > 0) { await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); } try { return(await QueryAsync(query).ConfigureAwait(false)); } catch (DynamoDbException ex) when(ex.IsTransient) { lastException = ex; } retryCount++; }while (retryPolicy.ShouldRetry(retryCount)); throw new DynamoDbException($"Error querying '{query.TableName}': {lastException.Message}", lastException); }
public async Task <CopyObjectResult> PutAsync( string name, S3ObjectLocation sourceLocation, IReadOnlyDictionary <string, string> metadata = null) { #region Preconditions if (name == null) { throw new ArgumentNullException(nameof(name)); } #endregion var retryCount = 0; Exception lastException = null; while (retryPolicy.ShouldRetry(retryCount)) { try { return(await PutInternalAsync(name, sourceLocation, metadata).ConfigureAwait(false)); } catch (S3Exception ex) when(ex.IsTransient) { lastException = ex; } retryCount++; await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); } throw new S3Exception($"Unrecoverable exception copying '{sourceLocation}' to '{name}'", lastException); }
public async Task DeleteAsync(params IQueueMessage <T>[] messages) { var handles = messages.Select(m => m.Receipt.Handle).ToArray(); var retryCount = 0; Exception lastError = null; do { try { await client.DeleteMessageBatchAsync(url, handles).ConfigureAwait(false); return; } catch (Exception ex) // TODO: Make sure it's recoverable { lastError = ex; } retryCount++; await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); }while (retryPolicy.ShouldRetry(retryCount)); throw lastError; }
public async Task DeleteAsync(params IQueueMessage <string>[] messages) { var receiptHandles = new string[messages.Length]; for (int i = 0; i < messages.Length; i++) { receiptHandles[i] = messages[i].Receipt.Handle; } var retryCount = 0; Exception lastError; do { try { await client.DeleteMessageBatchAsync(url, receiptHandles).ConfigureAwait(false); return; } catch (Exception ex) { // TODO: Make sure it's recoverable lastError = ex; } retryCount++; await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); }while (retryPolicy.ShouldRetry(retryCount)); throw lastError; }
private async Task <string> SendWithRetryPolicy(SesRequest request, RetryPolicy retryPolicy) { var retryCount = 0; Exception lastException; do { if (retryCount > 0) { await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); } try { return(await Send(request).ConfigureAwait(false)); } catch (SesException ex) when(ex.IsTransient) { lastException = ex; } retryCount++; }while (retryPolicy.ShouldRetry(retryCount)); throw lastException; }
internal async Task <T?> FindAsync(GetItemRequest request) { var retryCount = 0; Exception?lastException = null; do { if (retryCount > 0) { await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); } try { var result = await client.GetItemAsync(request).ConfigureAwait(false); // TODO: NotFound Handling if (result.Item is null) { return(null); } return(result.Item.As <T>(metadata)); } catch (DynamoDbException ex) when(ex.IsTransient) { lastException = ex; } retryCount++; }while (retryPolicy.ShouldRetry(retryCount)); var key = string.Join(",", request.Key.Select(k => k.Value)); var errorMessage = $"Unrecoverable exception getting '{key}' from '{tableName}'"; throw new Exception(errorMessage, lastException); }
public async Task <PutItemResult> PutItemUsingRetryPolicyAsync(PutItemRequest request, RetryPolicy retryPolicy) { var retryCount = 0; Exception lastError = null; do { try { return(await PutItemAsync(request).ConfigureAwait(false)); } catch (DynamoDbException ex) when(ex.IsTransient) { lastError = ex; } retryCount++; await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); }while (retryPolicy.ShouldRetry(retryCount)); throw lastError; }
public async Task <UpdateItemResult> UpdateItemWithRetryPolicy(UpdateItemRequest request, RetryPolicy retryPolicy) { var retryCount = 0; Exception lastError = null; while (retryPolicy.ShouldRetry(retryCount)) { try { return(await UpdateItem(request).ConfigureAwait(false)); } catch (DynamoDbException ex) when(ex.IsTransient) { lastError = ex; } retryCount++; await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false); } throw lastError; }