Example #1
0
        private static async Task SubmitBatchContent(IBaseClient client, Dictionary <string, Func <BatchRequestStep> > requests, bool ignoreNotFound, bool ignoreRefAlreadyExists, CancellationToken token, int attemptCount = 1)
        {
            BatchRequestContent content = GraphHelper.BuildBatchRequest(requests);

            BatchResponseContent response = await GraphHelper.ExecuteWithRetryAndRateLimit(async() => await client.Batch.Request().PostAsync(content, token), token, content.BatchRequestSteps.Count + 1);

            List <GraphBatchResult> results = await GetBatchResults(await response.GetResponsesAsync(), ignoreNotFound, ignoreRefAlreadyExists, attemptCount <= MaxRetry);

            GraphHelper.ThrowOnExceptions(results);

            int retryInterval = 8 * attemptCount;
            Dictionary <string, Func <BatchRequestStep> > stepsToRetry = new Dictionary <string, Func <BatchRequestStep> >();

            foreach (var result in results.Where(t => t.IsRetryable))
            {
                retryInterval = Math.Max(result.RetryInterval, retryInterval);
                stepsToRetry.Add(result.ID, requests[result.ID]);
            }

            if (stepsToRetry.Count > 0)
            {
                logger.Info($"Sleeping for {retryInterval} before retrying after attempt {attemptCount}");
                await Task.Delay(TimeSpan.FromSeconds(retryInterval), token);

                await GraphHelper.SubmitBatchContent(client, stepsToRetry, ignoreNotFound, ignoreRefAlreadyExists, token, ++attemptCount);
            }
        }