Skip to content

Commit fcd4f50

Browse files
feat(csharp): configurable retries on chunked helpers via ChunkedHelperOptions (generated)
algolia/api-clients-automation#6318 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
1 parent ca498ec commit fcd4f50

4 files changed

Lines changed: 170 additions & 65 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Algolia.Search.Utils;
2+
3+
/// <summary>
4+
/// Optional configuration for chunked helpers that batch records and poll for task completion.
5+
/// </summary>
6+
public class ChunkedHelperOptions
7+
{
8+
/// <summary>
9+
/// Maximum number of retries when polling for task completion. Defaults to <see cref="RetryHelper.DefaultMaxRetries"/>.
10+
/// </summary>
11+
public int MaxRetries { get; set; } = RetryHelper.DefaultMaxRetries;
12+
}

algoliasearch/Utils/IngestionClientExtensions.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Task<List<WatchResponse>> ChunkedPushAsync(
2828
int batchSize = 1000,
2929
string referenceIndexName = null,
3030
RequestOptions options = null,
31-
CancellationToken cancellationToken = default
31+
CancellationToken cancellationToken = default,
32+
ChunkedHelperOptions chunkedOptions = null
3233
);
3334

3435
/// <summary>
@@ -42,7 +43,8 @@ List<WatchResponse> ChunkedPush(
4243
int batchSize = 1000,
4344
string referenceIndexName = null,
4445
RequestOptions options = null,
45-
CancellationToken cancellationToken = default
46+
CancellationToken cancellationToken = default,
47+
ChunkedHelperOptions chunkedOptions = null
4648
);
4749
}
4850

@@ -61,6 +63,7 @@ public partial class IngestionClient : IIngestionClient
6163
/// <param name="referenceIndexName">This is required when targeting an index that does not have a push connector setup (e.g. a tmp index), but you wish to attach another index's transformation to it (e.g. the source index name).</param>
6264
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
6365
/// <param name="cancellationToken">Cancellation token to cancel the request</param>
66+
/// <param name="chunkedOptions">Optional configuration for the helper.</param>
6467
/// <returns>List of WatchResponse objects from the push operations</returns>
6568
public async Task<List<WatchResponse>> ChunkedPushAsync(
6669
string indexName,
@@ -70,9 +73,11 @@ public async Task<List<WatchResponse>> ChunkedPushAsync(
7073
int batchSize = 1000,
7174
string referenceIndexName = null,
7275
RequestOptions options = null,
73-
CancellationToken cancellationToken = default
76+
CancellationToken cancellationToken = default,
77+
ChunkedHelperOptions chunkedOptions = null
7478
)
7579
{
80+
var maxRetries = chunkedOptions?.MaxRetries ?? RetryHelper.DefaultMaxRetries;
7681
var objectsList = objects.ToList();
7782
var totalObjects = objectsList.Count;
7883
var responses = new List<WatchResponse>();
@@ -162,7 +167,7 @@ await RetryHelper
162167
}
163168
},
164169
eventResponse => eventResponse != null,
165-
maxRetries: 50,
170+
maxRetries: maxRetries,
166171
timeout: retryCount => Math.Min(retryCount * 1500, 5000),
167172
ct: cancellationToken
168173
)
@@ -196,7 +201,8 @@ public List<WatchResponse> ChunkedPush(
196201
int batchSize = 1000,
197202
string referenceIndexName = null,
198203
RequestOptions options = null,
199-
CancellationToken cancellationToken = default
204+
CancellationToken cancellationToken = default,
205+
ChunkedHelperOptions chunkedOptions = null
200206
) =>
201207
AsyncHelper.RunSync(() =>
202208
ChunkedPushAsync(
@@ -207,7 +213,8 @@ public List<WatchResponse> ChunkedPush(
207213
batchSize,
208214
referenceIndexName,
209215
options,
210-
cancellationToken
216+
cancellationToken,
217+
chunkedOptions
211218
)
212219
);
213220
}

algoliasearch/Utils/RetryHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class RetryHelper
1313
/// <summary>
1414
/// The default maximum number of retries
1515
/// </summary>
16-
public const int DefaultMaxRetries = 50;
16+
public const int DefaultMaxRetries = 100;
1717

1818
/// <summary>
1919
/// Retry the given function until the validation function returns true or the maximum number of retries is reached

0 commit comments

Comments
 (0)