feat: Salesforce - add urql/retry-exchange (#24302)
* Add .env variables * Add `urql/exchange-retry` * Add retry mechanic to graphql client * Only add retries if .env variables are set * Remove console.log
This commit is contained in:
1 parent
64f811ed0b
commit
4303fb8726
5 files changed
+64
-2
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { Client, cacheExchange, fetchExchange } from "@urql/core";
|
||||
import { retryExchange } from "@urql/exchange-retry";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
@@ -17,9 +18,27 @@ export class SalesforceGraphQLClient {
|
||||
|
||||
constructor({ accessToken, instanceUrl }: { accessToken: string; instanceUrl: string }) {
|
||||
this.accessToken = accessToken;
|
||||
|
||||
const exchanges = [cacheExchange, fetchExchange];
|
||||
|
||||
if (
|
||||
process.env.SALESFORCE_GRAPHQL_DELAY_MS &&
|
||||
process.env.SALESFORCE_GRAPHQL_MAX_DELAY_MS &&
|
||||
process.env.SALESFORCE_GRAPHQL_MAX_RETRIES
|
||||
) {
|
||||
const retryOptions = {
|
||||
maxRetries: 3,
|
||||
initialDelayMs: Number(process.env.SALESFORCE_GRAPHQL_DELAY_MS),
|
||||
maxDelayMs: Number(process.env.SALESFORCE_GRAPHQL_MAX_DELAY_MS),
|
||||
randomDelay: true,
|
||||
maxNumberAttempts: Number(process.env.SALESFORCE_GRAPHQL_MAX_RETRIES),
|
||||
};
|
||||
exchanges.push(retryExchange(retryOptions));
|
||||
}
|
||||
|
||||
this.client = new Client({
|
||||
url: `${instanceUrl}/services/data/${this.version}/graphql`,
|
||||
exchanges: [cacheExchange, fetchExchange],
|
||||
exchanges,
|
||||
fetchOptions: () => {
|
||||
return {
|
||||
headers: { authorization: `Bearer ${this.accessToken}` },
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
"@calcom/prisma": "workspace:*",
|
||||
"@jetstreamapp/soql-parser-js": "^6.1.0",
|
||||
"@jsforce/jsforce-node": "^3.6.3",
|
||||
"@urql/core": "^5.1.1"
|
||||
"@urql/core": "^5.1.1",
|
||||
"@urql/exchange-retry": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@calcom/types": "workspace:*",
|
||||
|
||||
Reference in new issue
Block a user