Skip to content

Commit

Permalink
Merge branch 'develop' into feat/register-resolve-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 9, 2025
2 parents 8af725f + 6778235 commit 34fe0c7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/afraid-experts-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

feat: add default retry strategy for redis
18 changes: 18 additions & 0 deletions packages/core/utils/src/common/__tests__/define-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -298,6 +301,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -462,6 +468,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -627,6 +636,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -780,6 +792,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down Expand Up @@ -933,6 +948,9 @@ describe("defineConfig", function () {
},
"storeCors": "http://localhost:8000",
},
"redisOptions": {
"retryStrategy": [Function],
},
},
}
`)
Expand Down
20 changes: 19 additions & 1 deletion packages/core/utils/src/common/define-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const DEFAULT_STORE_RESTRICTED_FIELDS = [
* to override configuration as needed.
*/
export function defineConfig(config: InputConfig = {}): ConfigModule {
const { http, ...restOfProjectConfig } = config.projectConfig || {}
const { http, redisOptions, ...restOfProjectConfig } =
config.projectConfig || {}

/**
* The defaults to use for the project config. They are shallow merged
Expand All @@ -57,6 +58,23 @@ export function defineConfig(config: InputConfig = {}): ConfigModule {
},
...http,
},
redisOptions: {
retryStrategy(retries) {
/**
* Exponentially increase delay with every retry
* attempt. Max to 4s
*/
const delay = Math.min(Math.pow(2, retries) * 50, 4000)

/**
* Add a random jitter to not choke the server when multiple
* clients are retrying at the same time
*/
const jitter = Math.floor(Math.random() * 200)
return delay + jitter
},
...redisOptions,
},
...restOfProjectConfig,
}

Expand Down

0 comments on commit 34fe0c7

Please sign in to comment.