@mimik/rediser 1.4.7 → 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.
Files changed (4) hide show
  1. package/.eslintrc +4 -4
  2. package/index.js +31 -11
  3. package/package.json +20 -24
  4. package/Gulpfile.js +0 -33
package/.eslintrc CHANGED
@@ -11,8 +11,9 @@
11
11
  },
12
12
  "extends": "airbnb",
13
13
  "rules": {
14
- "import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
15
- "brace-style": [1, "stroustrup", {"allowSingleLine": true}],
14
+ "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
15
+ "import/no-unresolved": ["error", { "amd": true, "commonjs": true, "caseSensitiveStrict": true }],
16
+ "brace-style": [1, "stroustrup", { "allowSingleLine": true }],
16
17
  "no-confusing-arrow": [0], // arrow isnt confusing
17
18
  "max-len": [1, 180, { "ignoreComments": true }],
18
19
  "linebreak-style": 0,
@@ -22,12 +23,11 @@
22
23
  "@mimik/document-env/validate-document-env": 2,
23
24
  "@mimik/dependencies/case-sensitive": 2,
24
25
  "@mimik/dependencies/no-cycles": 2,
25
- "@mimik/dependencies/no-unresolved": 2,
26
26
  "@mimik/dependencies/require-json-ext": 2
27
27
  },
28
28
  "settings":{
29
29
  "react": {
30
- "version": "latest"
30
+ "version": "detect"
31
31
  }
32
32
  },
33
33
  "globals": {
package/index.js CHANGED
@@ -8,8 +8,6 @@ const Promise = require('bluebird');
8
8
  * const redis = require('@mimik/rediser');
9
9
  */
10
10
 
11
- Promise.promisifyAll(redis.RedisClient.prototype);
12
-
13
11
  const type = 'redis';
14
12
  const correlationId = `${type}-cache-start@0/${new Date().toISOString()}`;
15
13
 
@@ -37,6 +35,28 @@ module.exports = (set, config) => {
37
35
  display = false;
38
36
  return null;
39
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
+
40
60
  if (display) {
41
61
  if (isProd(config.nodeEnvironment)) {
42
62
  const redisSettingsClone = { ...redisSettings };
@@ -46,21 +66,21 @@ module.exports = (set, config) => {
46
66
  }
47
67
  else logger.info('creating a cache connection', { type, settings: redisSettings }, correlationId);
48
68
  }
49
- display = false;
50
69
  const client = redis.createClient(redisSettings.url, redisSettings.options);
70
+ client.connect();
51
71
 
52
72
  client.on('error', (err) => {
53
73
  state = err;
54
74
  });
55
- client.on('reconnecting', () => {
56
- state = DISCONNECTED;
57
- });
75
+ client.on('reconnecting', disconnectHandler);
58
76
  client.on('ready', () => {
59
77
  state = CONNECTED;
78
+ if (interval) {
79
+ clearInterval(interval);
80
+ interval = null;
81
+ }
60
82
  });
61
- client.on('end', () => {
62
- state = DISCONNECTED;
63
- });
83
+ client.on('end', () => disconnectHandler);
64
84
 
65
85
  return client;
66
86
  };
@@ -83,7 +103,7 @@ module.exports = (set, config) => {
83
103
  if (set !== 'on') return Promise.resolve(null);
84
104
  const interval = setInterval(() => {
85
105
  if (state !== CONNECTED) {
86
- logger.error('fatal error: Timeout in connecting to database', {
106
+ logger.error('fatal error: Timeout in connecting to cache', {
87
107
  type, error: state, timeout: redisSettings.connectTimeout,
88
108
  }, correlationId);
89
109
  logger.flushAndExit(1);
@@ -92,7 +112,7 @@ module.exports = (set, config) => {
92
112
 
93
113
  return Promise.delay(VALIDATION_CHECK).then(() => {
94
114
  if (state !== DISCONNECTED && state !== CONNECTED) {
95
- const error = new Error(`connection not established: ${state}`);
115
+ const error = new Error(`cache connection not established: ${state}`);
96
116
 
97
117
  logger.error('cache connection error', { type, error }, correlationId);
98
118
  throw error;
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@mimik/rediser",
3
- "version": "1.4.7",
3
+ "version": "1.4.10",
4
4
  "description": "Helper for setting up redis using redis for mimik microservices",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "lint": "gulp lint",
8
- "docs": "gulp docs",
9
- "test": "exit 0",
10
- "prepublishOnly": "gulp docs; gulp lint; npm run test",
11
- "commit-ready": "gulp docs; gulp lint; npm run test",
7
+ "lint": "eslint --ignore-path .gitignore .",
8
+ "docs": "jsdoc2md index.js > README.md",
9
+ "test": "echo \"Error: no test specified\" && exit 0",
10
+ "test-ci": "echo \"Error: no test specified\" && exit 0",
11
+ "prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
12
+ "commit-ready": "npm run docs && npm run lint && npm run test-ci",
12
13
  "prepare": "husky install"
13
14
  },
14
15
  "husky": {
@@ -22,32 +23,27 @@
22
23
  "microservice"
23
24
  ],
24
25
  "author": "mimik technology inc <support@mimik.com> (https://developer.mimik.com/)",
25
- "license": "Apache-2.0",
26
+ "license": "MIT",
26
27
  "repository": {
27
28
  "type": "git",
28
29
  "url": "https://bitbucket.org/mimiktech/rediser"
29
30
  },
30
31
  "dependencies": {
31
- "@mimik/lib-filters": "^1.4.3",
32
- "@mimik/sumologic-winston-logger": "^1.6.6",
32
+ "@mimik/lib-filters": "^1.4.4",
33
+ "@mimik/sumologic-winston-logger": "^1.6.8",
33
34
  "bluebird": "3.7.2",
34
- "redis": "3.1.2"
35
+ "redis": "4.1.0"
35
36
  },
36
37
  "devDependencies": {
37
- "@mimik/eslint-plugin-dependencies": "^2.4.1",
38
- "@mimik/eslint-plugin-document-env": "^1.0.1",
39
- "eslint": "8.5.0",
40
- "eslint-config-airbnb": "18.2.1",
41
- "eslint-plugin-import": "2.25.3",
38
+ "@mimik/eslint-plugin-dependencies": "^2.4.3",
39
+ "@mimik/eslint-plugin-document-env": "^1.0.3",
40
+ "eslint": "8.15.0",
41
+ "eslint-config-airbnb": "19.0.4",
42
+ "eslint-plugin-import": "2.26.0",
42
43
  "eslint-plugin-jsx-a11y": "6.5.1",
43
- "eslint-plugin-react": "7.28.0",
44
- "eslint-plugin-react-hooks": "4.3.0",
45
- "fancy-log": "1.3.3",
46
- "gulp": "4.0.2",
47
- "gulp-eslint": "6.0.0",
48
- "gulp-git": "2.10.1",
49
- "gulp-rename": "2.0.0",
50
- "husky": "7.0.4",
51
- "jsdoc-to-markdown": "7.1.0"
44
+ "eslint-plugin-react": "7.29.4",
45
+ "eslint-plugin-react-hooks": "4.5.0",
46
+ "husky": "8.0.1",
47
+ "jsdoc-to-markdown": "7.1.1"
52
48
  }
53
49
  }
package/Gulpfile.js DELETED
@@ -1,33 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- const fs = require('fs');
3
- const log = require('fancy-log');
4
- const gulp = require('gulp');
5
- const eslint = require('gulp-eslint');
6
- const git = require('gulp-git');
7
- const jsdoc2md = require('jsdoc-to-markdown');
8
-
9
- const files = [
10
- 'index.js',
11
- 'Gulpfile.js',
12
- 'test/**.js',
13
- 'lib/**.js',
14
- ];
15
-
16
- const createDocs = (done) => {
17
- jsdoc2md.render({ files: 'index.js' })
18
- .then((output) => fs.writeFileSync('README.md', output))
19
- .catch((err) => log.error('docs creation failed:', err.message))
20
- .finally(() => done());
21
- };
22
-
23
- const lint = () => gulp.src(files)
24
- .pipe(eslint({}))
25
- .pipe(eslint.format());
26
-
27
- const add = () => gulp.src('README.md')
28
- .pipe(git.add({ quiet: true }));
29
-
30
- const docs = gulp.series(createDocs, add);
31
-
32
- gulp.task('docs', docs);
33
- gulp.task('lint', lint);