public override async Task <T> Get <T>(Guid id) { var attemptResult = new RetriableActivityOutcome <T>(); do { attemptResult = await this.Get <T>(id, attemptResult.AttemptsMade); } while (attemptResult.IsRetriable); if (attemptResult.WasSuccessful) { return(attemptResult.Result); } throw attemptResult.Exception; }
private async Task <RetriableActivityOutcome <T> > Get <T>(Guid id, int attempt) { try { // Make the attempt. var result = await base.Get <T>(id); return(RetriableActivityOutcome <T> .Successful(result, attempt + 1)); } catch (DocumentClientException ex) when(ex.StatusCode == (HttpStatusCode)429) { // Determine if we should retry based on this instances RetryOptions - the wait phase is baked into this method. if (!await this.IsRetriable(attempt)) { return(RetriableActivityOutcome <T> .Failure(ex, attempt + 1)); } // Recursively call this method. return(RetriableActivityOutcome <T> .Retriable(ex, attempt + 1)); } }