Skip to content

Commit

Permalink
feat: add default retry strategy for redis
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 8, 2025
1 parent 46f987e commit e79ed9e
Showing 1 changed file with 19 additions and 1 deletion.
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 @@ -74,7 +74,8 @@ type Config = Partial<
* to override configuration as needed.
*/
export function defineConfig(config: Config = {}): 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 @@ -93,6 +94,23 @@ export function defineConfig(config: Config = {}): 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 e79ed9e

Please sign in to comment.