-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic.js
109 lines (103 loc) · 2.24 KB
/
basic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import axios from "axios";
import reqque from "../src/reqque";
(async () => {
const requests = [
"https://httpstat.us/200?sleep=100",
"https://httpstat.us/400?sleep=290",
"https://httpstat.us/201?sleep=35",
"https://httpstat.us/500?sleep=700",
"https://httpstat.us/200?sleep=350",
"https://httpstat.us/200?sleep=450",
"https://httpstat.us/404?sleep=85",
];
const requestTemplate = async (url) => {
try {
const response = await axios.get(url);
return response.data;
} catch (e) {
return Promise.reject(e.response.data);
}
};
const config = {
maxRetries: 2,
batch: {
size: {
limit: 2,
},
},
delay: {
duration: {
limit: 1000,
},
},
};
const results = await reqque(requests, requestTemplate, config);
console.log(results); //eslint-disable-line
/*
[
{
"request": "https://httpstat.us/200?sleep=100",
"tryCount": 1,
"response": {
"code": 200,
"description": "OK"
},
"status": "successful"
},
{
"request": "https://httpstat.us/400?sleep=290",
"tryCount": 3,
"response": {
"code": 400,
"description": "Bad Request"
},
"status": "failed"
},
{
"request": "https://httpstat.us/201?sleep=35",
"tryCount": 1,
"response": {
"code": 201,
"description": "Created"
},
"status": "successful"
},
{
"request": "https://httpstat.us/500?sleep=700",
"tryCount": 3,
"response": {
"code": 500,
"description": "Internal Server Error"
},
"status": "failed"
},
{
"request": "https://httpstat.us/200?sleep=350",
"tryCount": 1,
"response": {
"code": 200,
"description": "OK"
},
"status": "successful"
},
{
"request": "https://httpstat.us/200?sleep=450",
"tryCount": 1,
"response": {
"code": 200,
"description": "OK"
},
"status": "successful"
},
{
"request": "https://httpstat.us/404?sleep=85",
"tryCount": 3,
"response": {
"code": 404,
"description": "Not Found"
},
"status": "failed"
}
]
*/
})();