Skip to content

Commit 6320cf9

Browse files
committed
feat(config): add support for timeout and retry config
- introduces two new extension parameters: - `TYPESENSE_CONNECTION_TIMEOUT_SECONDS` - `TYPESENSE_RETRY_INTERVAL_SECONDS` - updates `config.js` to parse values from environment variables - replaces random timeout values with user-defined config in `createTypesenseClient.js` - improves predictability and customizability of Typesense client behavior
1 parent b8952a4 commit 6320cf9

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

extension.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,19 @@ params:
348348
value: true
349349
default: false
350350
required: false
351+
- param: TYPESENSE_CONNECTION_TIMEOUT_SECONDS
352+
label: Typesense Connection Timeout (seconds)
353+
description: >-
354+
The timeout in seconds for connections to Typesense. This applies to both connection timeout.
355+
type: string
356+
example: "60"
357+
default: "60"
358+
required: false
359+
- param: TYPESENSE_RETRY_INTERVAL_SECONDS
360+
label: Typesense Retry Interval (seconds)
361+
description: >-
362+
The retry interval in seconds for connections to Typesense. This applies to both connection timeout.
363+
type: string
364+
example: "60"
365+
default: "60"
366+
required: false

functions/src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module.exports = {
1111
typesenseProtocol: process.env.TYPESENSE_PROTOCOL || "https",
1212
typesenseCollectionName: process.env.TYPESENSE_COLLECTION_NAME,
1313
typesenseAPIKey: process.env.TYPESENSE_API_KEY,
14+
typesenseConnectionTimeoutSeconds: parseInt(process.env.TYPESENSE_CONNECTION_TIMEOUT_SECONDS || "60", 10),
15+
typesenseRetryIntervalSeconds: parseInt(process.env.TYPESENSE_RETRY_INTERVAL_SECONDS || "60", 10),
1416
typesenseBackfillTriggerDocumentInFirestore: "typesense_sync/backfill",
1517
typesenseBackfillBatchSize: 1000,
1618
};
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
const config = require("./config.js");
22
const Typesense = require("typesense");
33

4-
// eslint-disable-next-line require-jsdoc
5-
function getRandomNumber(min, max) {
6-
return Math.floor(Math.random() * (max - min + 1)) + min;
7-
}
8-
94
module.exports = function () {
105
return new Typesense.Client({
116
nodes: config.typesenseHosts.map((h) => {
@@ -16,7 +11,7 @@ module.exports = function () {
1611
};
1712
}),
1813
apiKey: config.typesenseAPIKey,
19-
connectionTimeoutSeconds: getRandomNumber(60, 90),
20-
retryIntervalSeconds: getRandomNumber(60, 120),
14+
connectionTimeoutSeconds: config.typesenseConnectionTimeoutSeconds,
15+
retryIntervalSeconds: config.typesenseRetryIntervalSeconds,
2116
});
2217
};

0 commit comments

Comments
 (0)