@mimik/request-retry 2.0.10 → 2.0.12
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 +1 -6
- package/manual-test/man.js +2 -2
- package/manual-test/retryMockMan.js +5 -3
- package/manual-test/testEnv.js +23 -0
- package/manual-test/testRetry.js +3 -2
- package/package.json +2 -2
- package/test/testEnv.js +2 -0
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const Promise = require('bluebird');
|
|
2
|
-
const axios = require('axios');
|
|
3
2
|
|
|
4
3
|
const logger = require('@mimik/sumologic-winston-logger');
|
|
5
4
|
const { getRichError } = require('@mimik/response-helper');
|
|
@@ -69,8 +68,6 @@ Promise.config({ cancellation: true });
|
|
|
69
68
|
* - `qs` is used to assign to `params`
|
|
70
69
|
*/
|
|
71
70
|
const rpRetry = (origOptions) => {
|
|
72
|
-
const { CancelToken } = axios;
|
|
73
|
-
const source = CancelToken.source();
|
|
74
71
|
const options = origOptions;
|
|
75
72
|
const correlationId = (options.headers && options.headers['x-correlation-id']) ? options.headers['x-correlation-id'] : getCorrelationId();
|
|
76
73
|
const errors = [];
|
|
@@ -83,7 +80,6 @@ const rpRetry = (origOptions) => {
|
|
|
83
80
|
|
|
84
81
|
if (!options.headers) options.headers = { 'user-agent': setUserAgent() };
|
|
85
82
|
else if (!options.headers['user-agent']) options.headers['user-agent'] = setUserAgent();
|
|
86
|
-
options.cancelToken = source.token;
|
|
87
83
|
|
|
88
84
|
const retryProcess = (nbRetry) => rp(options)
|
|
89
85
|
.then((response) => {
|
|
@@ -130,8 +126,7 @@ const rpRetry = (origOptions) => {
|
|
|
130
126
|
const retryPromise = retryProcess(0);
|
|
131
127
|
const mainTimeoutPromise = new Promise((resolve, reject) => {
|
|
132
128
|
mainTimeout = setTimeout(() => {
|
|
133
|
-
delayPromises.forEach((delayPromise) => delayPromise.cancel(`retry timeout, ${criteria.timeout}, ${nbRetries}`));
|
|
134
|
-
source.cancel(`retry timeout, ${criteria.timeout}, ${nbRetries}`);
|
|
129
|
+
delayPromises.forEach((delayPromise) => delayPromise.cancel(`retry timeout delay, ${criteria.timeout}, ${nbRetries}`));
|
|
135
130
|
let error = new Error('retry timeout');
|
|
136
131
|
|
|
137
132
|
if (nbRetries !== 0) {
|
package/manual-test/man.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
require('
|
|
2
|
+
require('./testEnv');
|
|
3
3
|
|
|
4
4
|
const { rpRetry } = require('../index');
|
|
5
5
|
|
|
@@ -15,7 +15,7 @@ const options = {
|
|
|
15
15
|
retry: {},
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
options.retry.delayStrategy = () =>
|
|
18
|
+
options.retry.delayStrategy = () => 1000;
|
|
19
19
|
options.retry.timeout = 10;
|
|
20
20
|
options.retry.retries = 2;
|
|
21
21
|
|
|
@@ -11,6 +11,7 @@ const config = {
|
|
|
11
11
|
nbRetry: 400,
|
|
12
12
|
success: 200,
|
|
13
13
|
error: 500,
|
|
14
|
+
timeout: 4000,
|
|
14
15
|
},
|
|
15
16
|
post: {
|
|
16
17
|
success: 201,
|
|
@@ -37,9 +38,10 @@ app.get(`${config.base}${config.path}`, (req, res) => {
|
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
nbRequest += 1;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
res.statusCode = config.get.error;
|
|
43
|
+
res.send({ statusCode: config.get.error });
|
|
44
|
+
}, config.get.timeout);
|
|
43
45
|
});
|
|
44
46
|
app.post(`${config.base}${config.path}`, (req, res) => {
|
|
45
47
|
console.log('----->', 'Received a POST request');
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint no-process-env: "off" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The following environment variables are set for the test:
|
|
5
|
+
*
|
|
6
|
+
* | Env variable name | Description | Default | Comments |
|
|
7
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
8
|
+
* | SUMO_LOGIC_ENDPOINT | endpoint to use to log on sumologic | null
|
|
9
|
+
* | SUMO_LOGIC_COLLECTOR_CODE | code to use to log on sumologic | null
|
|
10
|
+
* | NO_STACK | flag to have a stack associated with the log | yes
|
|
11
|
+
* | LOG_LEVEL | log level to log | error
|
|
12
|
+
* | CONSOLE_LEVEL | log level to diplay | debug
|
|
13
|
+
* | LOG_MODE | log mode | none
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// process.env.SUMO_LOGIC_ENDPOINT = 'http://localhost:9080/logs/';
|
|
17
|
+
// process.env.SUMO_LOGIC_COLLECTOR_CODE = '1234';
|
|
18
|
+
process.env.SUMO_LOGIC_ENDPOINT = null;
|
|
19
|
+
process.env.SUMO_LOGIC_COLLECTOR_CODE = null;
|
|
20
|
+
process.env.NO_STACK = 'yes';
|
|
21
|
+
process.env.LOG_LEVEL = 'debug';
|
|
22
|
+
process.env.CONSOLE_LEVEL = 'debug';
|
|
23
|
+
process.env.LOG_MODE = 'none';
|
package/manual-test/testRetry.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
+
require('../test/testEnv');
|
|
2
3
|
const { rpRetry } = require('../index');
|
|
3
4
|
|
|
4
5
|
const options = {
|
|
5
6
|
method: 'GET',
|
|
6
|
-
url: 'http://blah.com', // 'http://localhost:9070/test/retry', // 'http://www.google.com', // 'http://localhost:8080/mIT/v1/admin/healthCheck1', // 'http://blah.com'
|
|
7
|
+
url: 'http://api.swaggerhub.com/apis/mimik/Boxes/1.2.1', // 'http://www.google.com', // 'http://blah.com', // 'http://localhost:9070/test/retry', // 'http://www.google.com', // 'http://localhost:8080/mIT/v1/admin/healthCheck1', // 'http://blah.com'
|
|
7
8
|
headers: {
|
|
8
9
|
'x-correlation-id': '---test-request-retry---',
|
|
9
10
|
},
|
|
10
11
|
json: true,
|
|
11
|
-
timeout:
|
|
12
|
+
timeout: 20000,
|
|
12
13
|
// retry: {
|
|
13
14
|
// all default: maxRetry: 2, retryDelay: 1000ms, maxTimeout: 50s, logLevel: 3 silly, type response, retryDelayStrategy: setDelay, retryStrategy: defaultRetry
|
|
14
15
|
// retries: -1, // => 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/request-retry",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "Request retry wrapping axios",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@mimik/request-helper": "^1.7.7",
|
|
33
33
|
"@mimik/response-helper": "^2.6.2",
|
|
34
34
|
"@mimik/sumologic-winston-logger": "^1.6.11",
|
|
35
|
-
"axios": "1.2.
|
|
35
|
+
"axios": "1.2.1",
|
|
36
36
|
"bluebird": "3.7.2",
|
|
37
37
|
"lodash": "4.17.21"
|
|
38
38
|
},
|
package/test/testEnv.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* | NO_STACK | flag to have a stack associated with the log | yes
|
|
11
11
|
* | LOG_LEVEL | log level to log | error
|
|
12
12
|
* | CONSOLE_LEVEL | log level to diplay | debug
|
|
13
|
+
* | LOG_MODE | log mode | none
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
// process.env.SUMO_LOGIC_ENDPOINT = 'http://localhost:9080/logs/';
|
|
@@ -19,3 +20,4 @@ process.env.SUMO_LOGIC_COLLECTOR_CODE = null;
|
|
|
19
20
|
process.env.NO_STACK = 'yes';
|
|
20
21
|
process.env.LOG_LEVEL = 'debug';
|
|
21
22
|
process.env.CONSOLE_LEVEL = 'debug';
|
|
23
|
+
process.env.LOG_MODE = 'none';
|