Skip to content

Commit 6b1a8c3

Browse files
Refactor example code
1 parent ee56593 commit 6b1a8c3

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

articles/governance/resource-graph/concepts/guidance-for-throttled-requests.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
title: Guidance for throttled requests
33
description: Learn to group, stagger, paginate, and query in parallel to avoid requests being throttled by Azure Resource Graph.
4-
ms.date: 09/13/2021
4+
author: timwarner-msft
5+
ms.author: timwarner
6+
ms.date: 08/18/2022
57
ms.topic: conceptual
68
ms.custom: devx-track-csharp
79
---
@@ -217,21 +219,21 @@ looking for. However, some Azure Resource Graph clients handle pagination differ
217219
```csharp
218220
var results = new List<object>();
219221
var queryRequest = new QueryRequest(
220-
subscriptions: new[] { mySubscriptionId },
221-
query: "Resources | project id, name, type");
222+
subscriptions: new[] { mySubscriptionId },
223+
query: "Resources | project id, name, type");
222224
var azureOperationResponse = await this.resourceGraphClient
223-
.ResourcesWithHttpMessagesAsync(queryRequest, header)
224-
.ConfigureAwait(false);
225-
while (!string.Empty(azureOperationResponse.Body.SkipToken))
225+
.ResourcesWithHttpMessagesAsync(queryRequest, header)
226+
.ConfigureAwait(false);
227+
while (!string.IsNullOrEmpty(azureOperationResponse.Body.SkipToken))
226228
{
227-
queryRequest.SkipToken = azureOperationResponse.Body.SkipToken;
228-
// Each post call to ResourceGraph consumes one query quota
229-
var azureOperationResponse = await this.resourceGraphClient
230-
.ResourcesWithHttpMessagesAsync(queryRequest, header)
231-
.ConfigureAwait(false);
232-
results.Add(azureOperationResponse.Body.Data.Rows);
229+
queryRequest.Options ??= new QueryRequestOptions();
230+
queryRequest.Options.SkipToken = azureOperationResponse.Body.SkipToken;
231+
var azureOperationResponse = await this.resourceGraphClient
232+
.ResourcesWithHttpMessagesAsync(queryRequest, header)
233+
.ConfigureAwait(false);
234+
results.Add(azureOperationResponse.Body.Data.Rows);
233235

234-
// Inspect throttling headers in query response and delay the next call if needed.
236+
// Inspect throttling headers in query response and delay the next call if needed.
235237
}
236238
```
237239

0 commit comments

Comments
 (0)