Skip to content

Commit 4ea9a7c

Browse files
authored
#2044 Add Ignore errors and timeout for ORM Cache (#2130)
Add Ignore errors and timeout for ORM cache
1 parent d5050a6 commit 4ea9a7c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

sources/packages/backend/libs/sims-db/src/data-source.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ import {
5454
ApplicationOfferingChangeRequest,
5555
} from "./entities";
5656
import { ClusterNode, ClusterOptions, RedisOptions } from "ioredis";
57-
import { ORM_CACHE_LIFETIME } from "@sims/utilities";
57+
import {
58+
ORM_CACHE_LIFETIME,
59+
ORM_CACHE_REDIS_COMMAND_TIMEOUT,
60+
ORM_CACHE_REDIS_RETRY_INTERVAL,
61+
} from "@sims/utilities";
5862
import { ConfigService } from "@sims/utilities/config";
5963

6064
interface ORMCacheConfig {
@@ -93,14 +97,22 @@ function getORMCacheConfig(): ORMCacheConfig | false {
9397
return false;
9498
}
9599

100+
const retryStrategy = (times: number) => {
101+
const delay = Math.min(times * 100, ORM_CACHE_REDIS_RETRY_INTERVAL);
102+
return delay;
103+
};
104+
96105
if (config.redis.redisStandaloneMode) {
97106
return {
98107
type: "ioredis",
99108
options: {
100109
host: config.redis.redisHost,
101110
port: config.redis.redisPort,
102111
password: config.redis.redisPassword,
112+
commandTimeout: ORM_CACHE_REDIS_COMMAND_TIMEOUT,
113+
retryStrategy,
103114
},
115+
ignoreErrors: true,
104116
duration: ORM_CACHE_LIFETIME,
105117
};
106118
}
@@ -113,9 +125,12 @@ function getORMCacheConfig(): ORMCacheConfig | false {
113125
options: {
114126
redisOptions: {
115127
password: config.redis.redisPassword,
128+
commandTimeout: ORM_CACHE_REDIS_COMMAND_TIMEOUT,
116129
},
130+
clusterRetryStrategy: retryStrategy,
117131
},
118132
},
133+
ignoreErrors: true,
119134
duration: ORM_CACHE_LIFETIME,
120135
};
121136
}

sources/packages/backend/libs/utilities/src/system-configurations-constants.ts

+16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ export const MIN_CANADA_LOAN_OVERAWARD = 250;
2424
* Default lifetime of ORM cache in milliseconds.
2525
*/
2626
export const ORM_CACHE_LIFETIME = 10 * 60 * 1000;
27+
28+
/**
29+
* Redis command timeout of the ORM cache in milliseconds.
30+
*/
31+
export const ORM_CACHE_REDIS_COMMAND_TIMEOUT = 5 * 1000;
32+
33+
/**
34+
* Redis retry interval to retry connection
35+
* when a connection cannot be established to redis.
36+
*
37+
* Ref for standalone: https://github.com/redis/ioredis/tree/v4#auto-reconnect
38+
*
39+
* Ref for cluster: https://github.com/redis/ioredis/tree/v4#cluster
40+
*/
41+
export const ORM_CACHE_REDIS_RETRY_INTERVAL = 60 * 1000;
42+
2743
/**
2844
* Minimum number of days from COE approval date to the disbursement date.
2945
*/

0 commit comments

Comments
 (0)