コード例 #1
0
        public async Task <T> Run <T>(BizwebRequestMessage baseReqMsg,
                                      ExecuteRequestAsync <T> executeRequestAsync)
        {
            while (true)
            {
                try
                {
                    using (var reqMsg = baseReqMsg.Clone())
                    {
                        var fullResult = await executeRequestAsync(reqMsg);

                        return(fullResult.Result);
                    }
                }
                catch (ApiRateLimitException)
                {
                    await Task.Delay(RETRY_DELAY);
                }
            }
        }
コード例 #2
0
        public async Task <T> Run <T>(IRestClient client, IRestRequest request, ExecuteRequestAsync <T> executeRequestAsync)
        {
            string      accessToken = this.GetAccessToken(client);
            LeakyBucket bucket      = null;

            if (accessToken != null)
            {
                bucket = _shopAccessTokenToLeakyBucket.GetOrAdd(accessToken, _ => new LeakyBucket());
            }

Start:
            if (accessToken != null)
            {
                await bucket.GrantAsync();
            }
            try
            {
                var requestResult = await executeRequestAsync();

                int?bucketContentSize = this.GetBucketContentSize(requestResult.Response);

                if (bucketContentSize != null)
                {
                    bucket?.SetContentSize(bucketContentSize.Value);
                }

                return(requestResult.Result);
            }
            catch (ShopifyRateLimitException)
            {
                //An exception may still occur:
                //-Shopify may have a slightly different algorithm
                //-Shopify may change to a different algorithm in the future
                //-There may be timing and latency delays
                //-Multiple programs may use the same access token
                //-Multiple instance of the same program may use the same access token
                await Task.Delay(THROTTLE_DELAY);

                goto Start;
            }
        }
コード例 #3
0
 public async Task <T> Run <T>(BizwebRequestMessage requestMsg,
                               ExecuteRequestAsync <T> executeRequestAsync)
 {
     return((await executeRequestAsync(requestMsg)).Result);
 }
コード例 #4
0
        public async Task <T> Run <T>(IFlurlClient request, HttpContent bodyContent, ExecuteRequestAsync <T> executeRequestAsync)
        {
            var fullResult = await executeRequestAsync(request, bodyContent);

            return(fullResult.Result);
        }