Skip to content

Commit c2e7520

Browse files
feat(javascript): expose maximum number of retries (generated)
algolia/api-clients-automation#6353 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 820b9d7 commit c2e7520

12 files changed

Lines changed: 144 additions & 49 deletions

File tree

packages/algoliasearch/builds/browser.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type Algoliasearch = SearchClient & {
6767
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
6868
* @param saveObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
6969
* @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
70+
* @param saveObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
7071
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push` method and merged with the transporter requestOptions.
7172
*/
7273
saveObjectsWithTransformation: (
@@ -84,6 +85,7 @@ export type Algoliasearch = SearchClient & {
8485
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail.
8586
* @param partialUpdateObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
8687
* @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
88+
* @param partialUpdateObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
8789
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push` method and merged with the transporter requestOptions.
8890
*/
8991
partialUpdateObjectsWithTransformation: (
@@ -100,6 +102,7 @@ export type Algoliasearch = SearchClient & {
100102
* @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
101103
* @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `objects.length / batchSize`. Defaults to 1000.
102104
* @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
105+
* @param replaceAllObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
103106
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push`, `operationIndex` and `getEvent` method and merged with the transporter requestOptions.
104107
*/
105108
replaceAllObjectsWithTransformation: (
@@ -162,7 +165,7 @@ export function algoliasearch(
162165
...client,
163166

164167
async saveObjectsWithTransformation(
165-
{ indexName, objects, waitForTasks },
168+
{ indexName, objects, waitForTasks, maxRetries },
166169
requestOptions,
167170
): Promise<Array<WatchResponse>> {
168171
if (!ingestionTransporter) {
@@ -172,13 +175,13 @@ export function algoliasearch(
172175
}
173176

174177
return ingestionTransporter.chunkedPush(
175-
{ indexName, objects, action: 'addObject', waitForTasks },
178+
{ indexName, objects, action: 'addObject', waitForTasks, maxRetries },
176179
requestOptions,
177180
);
178181
},
179182

180183
async partialUpdateObjectsWithTransformation(
181-
{ indexName, objects, createIfNotExists, waitForTasks },
184+
{ indexName, objects, createIfNotExists, waitForTasks, maxRetries },
182185
requestOptions,
183186
): Promise<Array<WatchResponse>> {
184187
if (!ingestionTransporter) {
@@ -193,13 +196,14 @@ export function algoliasearch(
193196
objects,
194197
action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate',
195198
waitForTasks,
199+
maxRetries,
196200
},
197201
requestOptions,
198202
);
199203
},
200204

201205
async replaceAllObjectsWithTransformation(
202-
{ indexName, objects, batchSize, scopes }: ReplaceAllObjectsOptions,
206+
{ indexName, objects, batchSize, scopes, maxRetries = 100 }: ReplaceAllObjectsOptions,
203207
requestOptions?: RequestOptions | undefined,
204208
): Promise<ReplaceAllObjectsWithTransformationResponse> {
205209
if (!ingestionTransporter) {
@@ -229,13 +233,21 @@ export function algoliasearch(
229233
);
230234

231235
const watchResponses = await ingestionTransporter.chunkedPush(
232-
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize, referenceIndexName: indexName },
236+
{
237+
indexName: tmpIndexName,
238+
objects,
239+
waitForTasks: true,
240+
batchSize,
241+
referenceIndexName: indexName,
242+
maxRetries,
243+
},
233244
requestOptions,
234245
);
235246

236247
await this.waitForTask({
237248
indexName: tmpIndexName,
238249
taskID: copyOperationResponse.taskID,
250+
maxRetries,
239251
});
240252

241253
copyOperationResponse = await this.operationIndex(
@@ -252,6 +264,7 @@ export function algoliasearch(
252264
await this.waitForTask({
253265
indexName: tmpIndexName,
254266
taskID: copyOperationResponse.taskID,
267+
maxRetries,
255268
});
256269

257270
const moveOperationResponse = await this.operationIndex(
@@ -264,6 +277,7 @@ export function algoliasearch(
264277
await this.waitForTask({
265278
indexName: tmpIndexName,
266279
taskID: moveOperationResponse.taskID,
280+
maxRetries,
267281
});
268282

269283
return { copyOperationResponse, watchResponses, moveOperationResponse };

packages/algoliasearch/builds/fetch.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type Algoliasearch = SearchClient & {
6767
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
6868
* @param saveObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
6969
* @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
70+
* @param saveObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
7071
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push` method and merged with the transporter requestOptions.
7172
*/
7273
saveObjectsWithTransformation: (
@@ -84,6 +85,7 @@ export type Algoliasearch = SearchClient & {
8485
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail.
8586
* @param partialUpdateObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
8687
* @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
88+
* @param partialUpdateObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
8789
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push` method and merged with the transporter requestOptions.
8890
*/
8991
partialUpdateObjectsWithTransformation: (
@@ -100,6 +102,7 @@ export type Algoliasearch = SearchClient & {
100102
* @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
101103
* @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `objects.length / batchSize`. Defaults to 1000.
102104
* @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
105+
* @param replaceAllObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
103106
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push`, `operationIndex` and `getEvent` method and merged with the transporter requestOptions.
104107
*/
105108
replaceAllObjectsWithTransformation: (
@@ -162,7 +165,7 @@ export function algoliasearch(
162165
...client,
163166

164167
async saveObjectsWithTransformation(
165-
{ indexName, objects, waitForTasks },
168+
{ indexName, objects, waitForTasks, maxRetries },
166169
requestOptions,
167170
): Promise<Array<WatchResponse>> {
168171
if (!ingestionTransporter) {
@@ -172,13 +175,13 @@ export function algoliasearch(
172175
}
173176

174177
return ingestionTransporter.chunkedPush(
175-
{ indexName, objects, action: 'addObject', waitForTasks },
178+
{ indexName, objects, action: 'addObject', waitForTasks, maxRetries },
176179
requestOptions,
177180
);
178181
},
179182

180183
async partialUpdateObjectsWithTransformation(
181-
{ indexName, objects, createIfNotExists, waitForTasks },
184+
{ indexName, objects, createIfNotExists, waitForTasks, maxRetries },
182185
requestOptions,
183186
): Promise<Array<WatchResponse>> {
184187
if (!ingestionTransporter) {
@@ -193,13 +196,14 @@ export function algoliasearch(
193196
objects,
194197
action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate',
195198
waitForTasks,
199+
maxRetries,
196200
},
197201
requestOptions,
198202
);
199203
},
200204

201205
async replaceAllObjectsWithTransformation(
202-
{ indexName, objects, batchSize, scopes }: ReplaceAllObjectsOptions,
206+
{ indexName, objects, batchSize, scopes, maxRetries = 100 }: ReplaceAllObjectsOptions,
203207
requestOptions?: RequestOptions | undefined,
204208
): Promise<ReplaceAllObjectsWithTransformationResponse> {
205209
if (!ingestionTransporter) {
@@ -229,13 +233,21 @@ export function algoliasearch(
229233
);
230234

231235
const watchResponses = await ingestionTransporter.chunkedPush(
232-
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize, referenceIndexName: indexName },
236+
{
237+
indexName: tmpIndexName,
238+
objects,
239+
waitForTasks: true,
240+
batchSize,
241+
referenceIndexName: indexName,
242+
maxRetries,
243+
},
233244
requestOptions,
234245
);
235246

236247
await this.waitForTask({
237248
indexName: tmpIndexName,
238249
taskID: copyOperationResponse.taskID,
250+
maxRetries,
239251
});
240252

241253
copyOperationResponse = await this.operationIndex(
@@ -252,6 +264,7 @@ export function algoliasearch(
252264
await this.waitForTask({
253265
indexName: tmpIndexName,
254266
taskID: copyOperationResponse.taskID,
267+
maxRetries,
255268
});
256269

257270
const moveOperationResponse = await this.operationIndex(
@@ -264,6 +277,7 @@ export function algoliasearch(
264277
await this.waitForTask({
265278
indexName: tmpIndexName,
266279
taskID: moveOperationResponse.taskID,
280+
maxRetries,
267281
});
268282

269283
return { copyOperationResponse, watchResponses, moveOperationResponse };

packages/algoliasearch/builds/node.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type Algoliasearch = SearchClient & {
6767
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
6868
* @param saveObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
6969
* @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
70+
* @param saveObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
7071
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push` method and merged with the transporter requestOptions.
7172
*/
7273
saveObjectsWithTransformation: (
@@ -84,6 +85,7 @@ export type Algoliasearch = SearchClient & {
8485
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail.
8586
* @param partialUpdateObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
8687
* @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
88+
* @param partialUpdateObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
8789
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push` method and merged with the transporter requestOptions.
8890
*/
8991
partialUpdateObjectsWithTransformation: (
@@ -100,6 +102,7 @@ export type Algoliasearch = SearchClient & {
100102
* @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
101103
* @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `objects.length / batchSize`. Defaults to 1000.
102104
* @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
105+
* @param replaceAllObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
103106
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `push`, `operationIndex` and `getEvent` method and merged with the transporter requestOptions.
104107
*/
105108
replaceAllObjectsWithTransformation: (
@@ -162,7 +165,7 @@ export function algoliasearch(
162165
...client,
163166

164167
async saveObjectsWithTransformation(
165-
{ indexName, objects, waitForTasks },
168+
{ indexName, objects, waitForTasks, maxRetries },
166169
requestOptions,
167170
): Promise<Array<WatchResponse>> {
168171
if (!ingestionTransporter) {
@@ -172,13 +175,13 @@ export function algoliasearch(
172175
}
173176

174177
return ingestionTransporter.chunkedPush(
175-
{ indexName, objects, action: 'addObject', waitForTasks },
178+
{ indexName, objects, action: 'addObject', waitForTasks, maxRetries },
176179
requestOptions,
177180
);
178181
},
179182

180183
async partialUpdateObjectsWithTransformation(
181-
{ indexName, objects, createIfNotExists, waitForTasks },
184+
{ indexName, objects, createIfNotExists, waitForTasks, maxRetries },
182185
requestOptions,
183186
): Promise<Array<WatchResponse>> {
184187
if (!ingestionTransporter) {
@@ -193,13 +196,14 @@ export function algoliasearch(
193196
objects,
194197
action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate',
195198
waitForTasks,
199+
maxRetries,
196200
},
197201
requestOptions,
198202
);
199203
},
200204

201205
async replaceAllObjectsWithTransformation(
202-
{ indexName, objects, batchSize, scopes }: ReplaceAllObjectsOptions,
206+
{ indexName, objects, batchSize, scopes, maxRetries = 100 }: ReplaceAllObjectsOptions,
203207
requestOptions?: RequestOptions | undefined,
204208
): Promise<ReplaceAllObjectsWithTransformationResponse> {
205209
if (!ingestionTransporter) {
@@ -229,13 +233,21 @@ export function algoliasearch(
229233
);
230234

231235
const watchResponses = await ingestionTransporter.chunkedPush(
232-
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize, referenceIndexName: indexName },
236+
{
237+
indexName: tmpIndexName,
238+
objects,
239+
waitForTasks: true,
240+
batchSize,
241+
referenceIndexName: indexName,
242+
maxRetries,
243+
},
233244
requestOptions,
234245
);
235246

236247
await this.waitForTask({
237248
indexName: tmpIndexName,
238249
taskID: copyOperationResponse.taskID,
250+
maxRetries,
239251
});
240252

241253
copyOperationResponse = await this.operationIndex(
@@ -252,6 +264,7 @@ export function algoliasearch(
252264
await this.waitForTask({
253265
indexName: tmpIndexName,
254266
taskID: copyOperationResponse.taskID,
267+
maxRetries,
255268
});
256269

257270
const moveOperationResponse = await this.operationIndex(
@@ -264,6 +277,7 @@ export function algoliasearch(
264277
await this.waitForTask({
265278
indexName: tmpIndexName,
266279
taskID: moveOperationResponse.taskID,
280+
maxRetries,
267281
});
268282

269283
return { copyOperationResponse, watchResponses, moveOperationResponse };

0 commit comments

Comments
 (0)