public AzureAtomicReader(CloudBlobClient storageClient, IDocumentStrategy strategy) { this._strategy = strategy; var folder = strategy.GetEntityBucket <TEntity>(); this._containerDirectory = storageClient.GetBlobDirectory(folder); this._logger = NetcoLogger.GetLogger(this.GetType()); this._ap = ActionPolicyAsync.From((exception => { var storageException = exception as StorageException; if (storageException == null) { return(false); } switch (storageException.RequestInformation.HttpStatusCode) { case ( int )HttpStatusCode.InternalServerError: case ( int )HttpStatusCode.ServiceUnavailable: return(true); default: return(false); } })).Retry(200, (ex, i) => { this._logger.Log().Trace(ex, "Retrying Azure API GET call: {0}/200", i); var secondsDelay = 0.2 + 0.1 * _random.Next(-1, 1); // randomize wait time Task.Delay(TimeSpan.FromSeconds(secondsDelay)).Wait(); }); }
public MagentoServiceLowLevel() { this.RepeatOnAuthProblemAsync = ActionPolicyAsync.From((exception => { var webException = (exception as MagentoWebException)?.InnerException as WebException; if (webException == null) { return(false); } switch (webException.Status) { case WebExceptionStatus.ProtocolError: var response = webException.Response as HttpWebResponse; if (response == null) { return(false); } switch (response.StatusCode) { case HttpStatusCode.Unauthorized: return(true); default: return(false); } default: return(false); } })) .RetryAsync(3, async(ex, i) => { await this._reauthorizeLock.WaitAsync(); var reauthorizationsCountPropagation = this.reauthorizationsCount; this._reauthorizeLock.Release(); await this._reauthorizeLock.WaitAsync(); try { if (reauthorizationsCountPropagation != this.reauthorizationsCount) { return; } Interlocked.Increment(ref this.reauthorizationsCount); MagentoLogger.Log().Trace(ex, "Retrying Magento API call due to authorization problem for the {0} time", i); await this.ReauthorizeAsync().ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(0.5 + i)).ConfigureAwait(false); } finally { this._reauthorizeLock.Release(); } }); }