@mimik/rediser 1.4.9 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +31 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -35,6 +35,28 @@ module.exports = (set, config) => {
|
|
|
35
35
|
display = false;
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
|
+
let interval;
|
|
39
|
+
const disconnectHandler = () => {
|
|
40
|
+
state = DISCONNECTED;
|
|
41
|
+
if (!interval) {
|
|
42
|
+
interval = setInterval(() => {
|
|
43
|
+
if (state !== CONNECTED) {
|
|
44
|
+
if (display) {
|
|
45
|
+
logger.error('fatal error: Timeout in connecting to cache', {
|
|
46
|
+
type, error: state, timeout: redisSettings.connectTimeout,
|
|
47
|
+
}, correlationId);
|
|
48
|
+
}
|
|
49
|
+
display = false;
|
|
50
|
+
logger.flushAndExit(1);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
clearInterval(interval);
|
|
54
|
+
interval = null;
|
|
55
|
+
}
|
|
56
|
+
}, config.redisSettings.connectTimeout * 1000); // convert in seconds
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
38
60
|
if (display) {
|
|
39
61
|
if (isProd(config.nodeEnvironment)) {
|
|
40
62
|
const redisSettingsClone = { ...redisSettings };
|
|
@@ -44,21 +66,21 @@ module.exports = (set, config) => {
|
|
|
44
66
|
}
|
|
45
67
|
else logger.info('creating a cache connection', { type, settings: redisSettings }, correlationId);
|
|
46
68
|
}
|
|
47
|
-
display = false;
|
|
48
69
|
const client = redis.createClient(redisSettings.url, redisSettings.options);
|
|
70
|
+
client.connect();
|
|
49
71
|
|
|
50
72
|
client.on('error', (err) => {
|
|
51
73
|
state = err;
|
|
52
74
|
});
|
|
53
|
-
client.on('reconnecting',
|
|
54
|
-
state = DISCONNECTED;
|
|
55
|
-
});
|
|
75
|
+
client.on('reconnecting', disconnectHandler);
|
|
56
76
|
client.on('ready', () => {
|
|
57
77
|
state = CONNECTED;
|
|
78
|
+
if (interval) {
|
|
79
|
+
clearInterval(interval);
|
|
80
|
+
interval = null;
|
|
81
|
+
}
|
|
58
82
|
});
|
|
59
|
-
client.on('end', () =>
|
|
60
|
-
state = DISCONNECTED;
|
|
61
|
-
});
|
|
83
|
+
client.on('end', () => disconnectHandler);
|
|
62
84
|
|
|
63
85
|
return client;
|
|
64
86
|
};
|
|
@@ -81,7 +103,7 @@ module.exports = (set, config) => {
|
|
|
81
103
|
if (set !== 'on') return Promise.resolve(null);
|
|
82
104
|
const interval = setInterval(() => {
|
|
83
105
|
if (state !== CONNECTED) {
|
|
84
|
-
logger.error('fatal error: Timeout in connecting to
|
|
106
|
+
logger.error('fatal error: Timeout in connecting to cache', {
|
|
85
107
|
type, error: state, timeout: redisSettings.connectTimeout,
|
|
86
108
|
}, correlationId);
|
|
87
109
|
logger.flushAndExit(1);
|
|
@@ -90,7 +112,7 @@ module.exports = (set, config) => {
|
|
|
90
112
|
|
|
91
113
|
return Promise.delay(VALIDATION_CHECK).then(() => {
|
|
92
114
|
if (state !== DISCONNECTED && state !== CONNECTED) {
|
|
93
|
-
const error = new Error(`connection not established: ${state}`);
|
|
115
|
+
const error = new Error(`cache connection not established: ${state}`);
|
|
94
116
|
|
|
95
117
|
logger.error('cache connection error', { type, error }, correlationId);
|
|
96
118
|
throw error;
|