Skip to content

Commit e168682

Browse files
fix(clients): WithTransformation methods retry logic (#5183) (generated) [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent ede5ee0 commit e168682

File tree

13 files changed

+133
-36
lines changed

13 files changed

+133
-36
lines changed

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6760,6 +6760,25 @@ public <T> List<WatchResponse> saveObjectsWithTransformation(String indexName, I
67606760
return saveObjectsWithTransformation(indexName, objects, null);
67616761
}
67626762

6763+
/**
6764+
* Helper: Similar to the `saveObjects` method but requires a Push connector
6765+
* (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/)
6766+
* to be created first, in order to transform records before indexing them to Algolia. The
6767+
* `region` must have been passed to the client instantiation method.
6768+
*
6769+
* @param indexName The `indexName` to replace `objects` in.
6770+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
6771+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been
6772+
* processed, this operation may slow the total execution time of this method but is more
6773+
* reliable.
6774+
* @throws AlgoliaRetryException When the retry has failed on all hosts
6775+
* @throws AlgoliaApiException When the API sends an http error code
6776+
* @throws AlgoliaRuntimeException When an error occurred during the serialization
6777+
*/
6778+
public <T> List<WatchResponse> saveObjectsWithTransformation(String indexName, Iterable<T> objects, boolean waitForTasks) {
6779+
return saveObjectsWithTransformation(indexName, objects, waitForTasks, null);
6780+
}
6781+
67636782
/**
67646783
* Helper: Similar to the `saveObjects` method but requires a Push connector
67656784
* (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/)

clients/algoliasearch-client-php/lib/Configuration/IngestionConfig.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class IngestionConfig extends ConfigWithRegion
1010
{
1111
protected $clientName = 'Ingestion';
1212

13+
private $defaultWaitTaskTimeBeforeRetry = 5000; // 5 sec in milliseconds
14+
1315
public static function create($appId, $apiKey, $region = null)
1416
{
1517
$allowedRegions = ['eu', 'us'];
@@ -27,6 +29,11 @@ public static function create($appId, $apiKey, $region = null)
2729
return parent::create($appId, $apiKey, $region);
2830
}
2931

32+
public function getWaitTaskTimeBeforeRetry()
33+
{
34+
return $this->config['waitTaskTimeBeforeRetry'];
35+
}
36+
3037
public function getDefaultConfiguration()
3138
{
3239
return [
@@ -38,6 +45,7 @@ public function getDefaultConfiguration()
3845
'writeTimeout' => 25,
3946
'connectTimeout' => 25,
4047
'defaultHeaders' => [],
48+
'waitTaskTimeBeforeRetry' => $this->defaultWaitTaskTimeBeforeRetry,
4149
];
4250
}
4351
}

docs/bundled/search-snippets.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@
13621362
"call partialUpdateObjects with createIfNotExists=false": "response, err := client.PartialUpdateObjects(\n \"<YOUR_INDEX_NAME>\",\n []map[string]any{map[string]any{\"objectID\": \"3\", \"name\": \"Cyril\"}, map[string]any{\"objectID\": \"4\", \"name\": \"David\"}}, search.WithCreateIfNotExists(false))\nif err != nil {\n // handle the eventual error\n panic(err)\n}"
13631363
},
13641364
"partialUpdateObjectsWithTransformation": {
1365-
"default": "response, err := client.PartialUpdateObjectsWithTransformation(\n \"<YOUR_INDEX_NAME>\",\n []map[string]any{map[string]any{\"objectID\": \"1\", \"name\": \"Adam\"}, map[string]any{\"objectID\": \"2\", \"name\": \"Benoit\"}}, search.WithCreateIfNotExists(true))\nif err != nil {\n // handle the eventual error\n panic(err)\n}"
1365+
"default": "response, err := client.PartialUpdateObjectsWithTransformation(\n \"<YOUR_INDEX_NAME>\",\n []map[string]any{map[string]any{\"objectID\": \"1\", \"name\": \"Adam\"}, map[string]any{\"objectID\": \"2\", \"name\": \"Benoit\"}}, search.WithCreateIfNotExists(true), search.WithWaitForTasks(true))\nif err != nil {\n // handle the eventual error\n panic(err)\n}"
13661366
},
13671367
"removeUserId": {
13681368
"default": "response, err := client.RemoveUserId(client.NewApiRemoveUserIdRequest(\n \"uniqueID\"))\nif err != nil {\n // handle the eventual error\n panic(err)\n}"
@@ -1391,7 +1391,7 @@
13911391
"saveObjectsPublicUser": "response, err := client.SaveObjects(\n \"<YOUR_INDEX_NAME>\",\n []map[string]any{map[string]any{\"objectID\": \"1\", \"visibility\": \"public\", \"name\": \"Hot 100 Billboard Charts\", \"playlistId\": \"d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f\", \"createdAt\": \"1500240452\"}}, search.WithWaitForTasks(false), search.WithBatchSize(1000), search.WithHeaderParam(\"X-Algolia-User-ID\", \"*\"))\nif err != nil {\n // handle the eventual error\n panic(err)\n}"
13921392
},
13931393
"saveObjectsWithTransformation": {
1394-
"default": "response, err := client.SaveObjectsWithTransformation(\n \"<YOUR_INDEX_NAME>\",\n []map[string]any{map[string]any{\"objectID\": \"1\", \"name\": \"Adam\"}, map[string]any{\"objectID\": \"2\", \"name\": \"Benoit\"}})\nif err != nil {\n // handle the eventual error\n panic(err)\n}"
1394+
"default": "response, err := client.SaveObjectsWithTransformation(\n \"<YOUR_INDEX_NAME>\",\n []map[string]any{map[string]any{\"objectID\": \"1\", \"name\": \"Adam\"}, map[string]any{\"objectID\": \"2\", \"name\": \"Benoit\"}}, search.WithWaitForTasks(true))\nif err != nil {\n // handle the eventual error\n panic(err)\n}"
13951395
},
13961396
"saveRule": {
13971397
"saveRule with minimal parameters": "response, err := client.SaveRule(client.NewApiSaveRuleRequest(\n \"<YOUR_INDEX_NAME>\", \"id1\",\n search.NewEmptyRule().SetObjectID(\"id1\").SetConditions(\n []search.Condition{*search.NewEmptyCondition().SetPattern(\"apple\").SetAnchoring(search.Anchoring(\"contains\"))}).SetConsequence(\n search.NewEmptyConsequence().SetParams(\n search.NewEmptyConsequenceParams().SetFilters(\"brand:xiaomi\")))))\nif err != nil {\n // handle the eventual error\n panic(err)\n}",
@@ -1952,7 +1952,7 @@
19521952
"call partialUpdateObjects with createIfNotExists=false": "client.partialUpdateObjects(\n \"<YOUR_INDEX_NAME>\",\n Arrays.asList(\n new HashMap() {\n {\n put(\"objectID\", \"3\");\n put(\"name\", \"Cyril\");\n }\n },\n new HashMap() {\n {\n put(\"objectID\", \"4\");\n put(\"name\", \"David\");\n }\n }\n ),\n false\n);"
19531953
},
19541954
"partialUpdateObjectsWithTransformation": {
1955-
"default": "client.partialUpdateObjectsWithTransformation(\n \"<YOUR_INDEX_NAME>\",\n Arrays.asList(\n new HashMap() {\n {\n put(\"objectID\", \"1\");\n put(\"name\", \"Adam\");\n }\n },\n new HashMap() {\n {\n put(\"objectID\", \"2\");\n put(\"name\", \"Benoit\");\n }\n }\n ),\n true\n);"
1955+
"default": "client.partialUpdateObjectsWithTransformation(\n \"<YOUR_INDEX_NAME>\",\n Arrays.asList(\n new HashMap() {\n {\n put(\"objectID\", \"1\");\n put(\"name\", \"Adam\");\n }\n },\n new HashMap() {\n {\n put(\"objectID\", \"2\");\n put(\"name\", \"Benoit\");\n }\n }\n ),\n true,\n true\n);"
19561956
},
19571957
"removeUserId": {
19581958
"default": "client.removeUserId(\"uniqueID\");"
@@ -1981,7 +1981,7 @@
19811981
"saveObjectsPublicUser": "client.saveObjects(\n \"<YOUR_INDEX_NAME>\",\n Arrays.asList(\n new HashMap() {\n {\n put(\"objectID\", \"1\");\n put(\"visibility\", \"public\");\n put(\"name\", \"Hot 100 Billboard Charts\");\n put(\"playlistId\", \"d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f\");\n put(\"createdAt\", \"1500240452\");\n }\n }\n ),\n false,\n 1000,\n new RequestOptions().addExtraHeader(\"X-Algolia-User-ID\", \"*\")\n);"
19821982
},
19831983
"saveObjectsWithTransformation": {
1984-
"default": "client.saveObjectsWithTransformation(\n \"<YOUR_INDEX_NAME>\",\n Arrays.asList(\n new HashMap() {\n {\n put(\"objectID\", \"1\");\n put(\"name\", \"Adam\");\n }\n },\n new HashMap() {\n {\n put(\"objectID\", \"2\");\n put(\"name\", \"Benoit\");\n }\n }\n )\n);"
1984+
"default": "client.saveObjectsWithTransformation(\n \"<YOUR_INDEX_NAME>\",\n Arrays.asList(\n new HashMap() {\n {\n put(\"objectID\", \"1\");\n put(\"name\", \"Adam\");\n }\n },\n new HashMap() {\n {\n put(\"objectID\", \"2\");\n put(\"name\", \"Benoit\");\n }\n }\n ),\n true\n);"
19851985
},
19861986
"saveRule": {
19871987
"saveRule with minimal parameters": "client.saveRule(\n \"<YOUR_INDEX_NAME>\",\n \"id1\",\n new Rule()\n .setObjectID(\"id1\")\n .setConditions(Arrays.asList(new Condition().setPattern(\"apple\").setAnchoring(Anchoring.CONTAINS)))\n .setConsequence(new Consequence().setParams(new ConsequenceParams().setFilters(\"brand:xiaomi\")))\n);",
@@ -2545,7 +2545,7 @@
25452545
"call partialUpdateObjects with createIfNotExists=false": "const response = await client.partialUpdateObjects({\n indexName: 'cts_e2e_partialUpdateObjects_javascript',\n objects: [\n { objectID: '3', name: 'Cyril' },\n { objectID: '4', name: 'David' },\n ],\n createIfNotExists: false,\n});"
25462546
},
25472547
"partialUpdateObjectsWithTransformation": {
2548-
"default": "const response = await client.partialUpdateObjectsWithTransformation({\n indexName: 'cts_e2e_partialUpdateObjectsWithTransformation_javascript',\n objects: [\n { objectID: '1', name: 'Adam' },\n { objectID: '2', name: 'Benoit' },\n ],\n createIfNotExists: true,\n});"
2548+
"default": "const response = await client.partialUpdateObjectsWithTransformation({\n indexName: 'cts_e2e_partialUpdateObjectsWithTransformation_javascript',\n objects: [\n { objectID: '1', name: 'Adam' },\n { objectID: '2', name: 'Benoit' },\n ],\n createIfNotExists: true,\n waitForTasks: true,\n});"
25492549
},
25502550
"removeUserId": {
25512551
"default": "const response = await client.removeUserId({ userID: 'uniqueID' });"
@@ -2574,7 +2574,7 @@
25742574
"saveObjectsPublicUser": "const response = await client.saveObjects(\n {\n indexName: 'playlists',\n objects: [\n {\n objectID: '1',\n visibility: 'public',\n name: 'Hot 100 Billboard Charts',\n playlistId: 'd3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f',\n createdAt: '1500240452',\n },\n ],\n waitForTasks: false,\n batchSize: 1000,\n },\n {\n headers: { 'X-Algolia-User-ID': '*' },\n },\n);"
25752575
},
25762576
"saveObjectsWithTransformation": {
2577-
"default": "const response = await client.saveObjectsWithTransformation({\n indexName: 'cts_e2e_saveObjectsWithTransformation_javascript',\n objects: [\n { objectID: '1', name: 'Adam' },\n { objectID: '2', name: 'Benoit' },\n ],\n});"
2577+
"default": "const response = await client.saveObjectsWithTransformation({\n indexName: 'cts_e2e_saveObjectsWithTransformation_javascript',\n objects: [\n { objectID: '1', name: 'Adam' },\n { objectID: '2', name: 'Benoit' },\n ],\n waitForTasks: true,\n});"
25782578
},
25792579
"saveRule": {
25802580
"saveRule with minimal parameters": "const response = await client.saveRule({\n indexName: 'indexName',\n objectID: 'id1',\n rule: {\n objectID: 'id1',\n conditions: [{ pattern: 'apple', anchoring: 'contains' }],\n consequence: { params: { filters: 'brand:xiaomi' } },\n },\n});",
@@ -3716,7 +3716,7 @@
37163716
"call partialUpdateObjects with createIfNotExists=false": "$response = $client->partialUpdateObjects(\n '<YOUR_INDEX_NAME>',\n [\n ['objectID' => '3',\n 'name' => 'Cyril',\n ],\n\n ['objectID' => '4',\n 'name' => 'David',\n ],\n ],\n false,\n);"
37173717
},
37183718
"partialUpdateObjectsWithTransformation": {
3719-
"default": "$response = $client->partialUpdateObjectsWithTransformation(\n '<YOUR_INDEX_NAME>',\n [\n ['objectID' => '1',\n 'name' => 'Adam',\n ],\n\n ['objectID' => '2',\n 'name' => 'Benoit',\n ],\n ],\n true,\n);"
3719+
"default": "$response = $client->partialUpdateObjectsWithTransformation(\n '<YOUR_INDEX_NAME>',\n [\n ['objectID' => '1',\n 'name' => 'Adam',\n ],\n\n ['objectID' => '2',\n 'name' => 'Benoit',\n ],\n ],\n true,\n true,\n);"
37203720
},
37213721
"removeUserId": {
37223722
"default": "$response = $client->removeUserId(\n 'uniqueID',\n);"
@@ -3745,7 +3745,7 @@
37453745
"saveObjectsPublicUser": "$response = $client->saveObjects(\n '<YOUR_INDEX_NAME>',\n [\n ['objectID' => '1',\n 'visibility' => 'public',\n 'name' => 'Hot 100 Billboard Charts',\n 'playlistId' => 'd3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f',\n 'createdAt' => '1500240452',\n ],\n ],\n false,\n 1000,\n [\n 'headers' => [\n 'X-Algolia-User-ID' => '*',\n ],\n ]\n);"
37463746
},
37473747
"saveObjectsWithTransformation": {
3748-
"default": "$response = $client->saveObjectsWithTransformation(\n '<YOUR_INDEX_NAME>',\n [\n ['objectID' => '1',\n 'name' => 'Adam',\n ],\n\n ['objectID' => '2',\n 'name' => 'Benoit',\n ],\n ],\n);"
3748+
"default": "$response = $client->saveObjectsWithTransformation(\n '<YOUR_INDEX_NAME>',\n [\n ['objectID' => '1',\n 'name' => 'Adam',\n ],\n\n ['objectID' => '2',\n 'name' => 'Benoit',\n ],\n ],\n true,\n);"
37493749
},
37503750
"saveRule": {
37513751
"saveRule with minimal parameters": "$response = $client->saveRule(\n '<YOUR_INDEX_NAME>',\n 'id1',\n ['objectID' => 'id1',\n 'conditions' => [\n ['pattern' => 'apple',\n 'anchoring' => 'contains',\n ],\n ],\n 'consequence' => ['params' => ['filters' => 'brand:xiaomi',\n ],\n ],\n ],\n);",
@@ -4306,7 +4306,7 @@
43064306
"call partialUpdateObjects with createIfNotExists=false": "response = client.partial_update_objects(\n index_name=\"<YOUR_INDEX_NAME>\",\n objects=[\n {\n \"objectID\": \"3\",\n \"name\": \"Cyril\",\n },\n {\n \"objectID\": \"4\",\n \"name\": \"David\",\n },\n ],\n create_if_not_exists=False,\n)"
43074307
},
43084308
"partialUpdateObjectsWithTransformation": {
4309-
"default": "response = client.partial_update_objects_with_transformation(\n index_name=\"<YOUR_INDEX_NAME>\",\n objects=[\n {\n \"objectID\": \"1\",\n \"name\": \"Adam\",\n },\n {\n \"objectID\": \"2\",\n \"name\": \"Benoit\",\n },\n ],\n create_if_not_exists=True,\n)"
4309+
"default": "response = client.partial_update_objects_with_transformation(\n index_name=\"<YOUR_INDEX_NAME>\",\n objects=[\n {\n \"objectID\": \"1\",\n \"name\": \"Adam\",\n },\n {\n \"objectID\": \"2\",\n \"name\": \"Benoit\",\n },\n ],\n create_if_not_exists=True,\n wait_for_tasks=True,\n)"
43104310
},
43114311
"removeUserId": {
43124312
"default": "response = client.remove_user_id(\n user_id=\"uniqueID\",\n)"
@@ -4335,7 +4335,7 @@
43354335
"saveObjectsPublicUser": "response = client.save_objects(\n index_name=\"<YOUR_INDEX_NAME>\",\n objects=[\n {\n \"objectID\": \"1\",\n \"visibility\": \"public\",\n \"name\": \"Hot 100 Billboard Charts\",\n \"playlistId\": \"d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f\",\n \"createdAt\": \"1500240452\",\n },\n ],\n wait_for_tasks=False,\n batch_size=1000,\n request_options={\n \"headers\": loads(\"\"\"{\"X-Algolia-User-ID\":\"*\"}\"\"\"),\n },\n)"
43364336
},
43374337
"saveObjectsWithTransformation": {
4338-
"default": "response = client.save_objects_with_transformation(\n index_name=\"<YOUR_INDEX_NAME>\",\n objects=[\n {\n \"objectID\": \"1\",\n \"name\": \"Adam\",\n },\n {\n \"objectID\": \"2\",\n \"name\": \"Benoit\",\n },\n ],\n)"
4338+
"default": "response = client.save_objects_with_transformation(\n index_name=\"<YOUR_INDEX_NAME>\",\n objects=[\n {\n \"objectID\": \"1\",\n \"name\": \"Adam\",\n },\n {\n \"objectID\": \"2\",\n \"name\": \"Benoit\",\n },\n ],\n wait_for_tasks=True,\n)"
43394339
},
43404340
"saveRule": {
43414341
"saveRule with minimal parameters": "response = client.save_rule(\n index_name=\"<YOUR_INDEX_NAME>\",\n object_id=\"id1\",\n rule={\n \"objectID\": \"id1\",\n \"conditions\": [\n {\n \"pattern\": \"apple\",\n \"anchoring\": \"contains\",\n },\n ],\n \"consequence\": {\n \"params\": {\n \"filters\": \"brand:xiaomi\",\n },\n },\n },\n)",

docs/snippets/go/src/search.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/snippets/java/src/test/java/com/algolia/Search.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,7 @@ void snippetForPartialUpdateObjectsWithTransformation() throws Exception {
19671967
}
19681968
}
19691969
),
1970+
true,
19701971
true
19711972
);
19721973
// >LOG
@@ -2400,7 +2401,8 @@ void snippetForSaveObjectsWithTransformation() throws Exception {
24002401
put("name", "Benoit");
24012402
}
24022403
}
2403-
)
2404+
),
2405+
true
24042406
);
24052407
// >LOG
24062408
// SEPARATOR<

docs/snippets/javascript/src/search.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,7 @@ export async function snippetForPartialUpdateObjectsWithTransformation(): Promis
20812081
{ objectID: '2', name: 'Benoit' },
20822082
],
20832083
createIfNotExists: true,
2084+
waitForTasks: true,
20842085
});
20852086

20862087
// >LOG
@@ -2414,6 +2415,7 @@ export async function snippetForSaveObjectsWithTransformation(): Promise<void> {
24142415
{ objectID: '1', name: 'Adam' },
24152416
{ objectID: '2', name: 'Benoit' },
24162417
],
2418+
waitForTasks: true,
24172419
});
24182420

24192421
// >LOG

docs/snippets/php/src/Search.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,6 +2616,7 @@ public function snippetForPartialUpdateObjectsWithTransformation(): void
26162616
],
26172617
],
26182618
true,
2619+
true,
26192620
);
26202621

26212622
// >LOG
@@ -3069,6 +3070,7 @@ public function snippetForSaveObjectsWithTransformation(): void
30693070
'name' => 'Benoit',
30703071
],
30713072
],
3073+
true,
30723074
);
30733075

30743076
// >LOG

docs/snippets/python/search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,6 +2677,7 @@ def snippet_for_partial_update_objects_with_transformation():
26772677
},
26782678
],
26792679
create_if_not_exists=True,
2680+
wait_for_tasks=True,
26802681
)
26812682

26822683
# >LOG
@@ -3138,6 +3139,7 @@ def snippet_for_save_objects_with_transformation():
31383139
"name": "Benoit",
31393140
},
31403141
],
3142+
wait_for_tasks=True,
31413143
)
31423144

31433145
# >LOG

0 commit comments

Comments
 (0)