Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit f6f49da

Browse files
committed
Fix rate limit of 600 requests per minutes on Gitlab.com
This is a simple fix, maximum of 10 requests per seconds = maximum of 600 requests per minutes. It does slow down a bit the report but it prevent a fatal error. It's possible to design a more sophisticated fix but it will be more complex with more states to manage. It would be more prone to bugs. I favor simplicity over maximum speed.
1 parent e059f1f commit f6f49da

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"request-promise-native": "^1.0.4",
5858
"shelljs": "^0.8.3",
5959
"tempfile": "^2.0.0",
60+
"throttled-queue": "^1.0.7",
6061
"underscore": "^1.9.1",
6162
"xdg-basedir": "^3.0.0",
6263
"xlsx": "^0.13.5"

src/models/base.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const request = require('request-promise-native');
22
const url = require('url');
33
const async = require('async');
44
const crypto = require('crypto');
5+
const throttledQueue = require('throttled-queue');
6+
7+
const throttle = throttledQueue(10, 1000);
58

69
/**
710
* base model
@@ -36,19 +39,21 @@ class base {
3639
data.private_token = this.token;
3740

3841
return new Promise((resolve, reject) => {
39-
request.post(`${this.url}${path}`, {
40-
json: true,
41-
body: data,
42-
insecure: this._insecure,
43-
proxy: this._proxy,
44-
resolveWithFullResponse: true,
45-
headers: {
46-
'PRIVATE-TOKEN': this.token
47-
}
48-
}).then(response => {
49-
if (this.config.get('_createDump')) this.setDump(response, key);
50-
resolve(response);
51-
}).catch(e => reject(e));
42+
throttle(() => {
43+
request.post(`${this.url}${path}`, {
44+
json: true,
45+
body: data,
46+
insecure: this._insecure,
47+
proxy: this._proxy,
48+
resolveWithFullResponse: true,
49+
headers: {
50+
'PRIVATE-TOKEN': this.token
51+
}
52+
}).then(response => {
53+
if (this.config.get('_createDump')) this.setDump(response, key);
54+
resolve(response);
55+
}).catch(e => reject(e));
56+
})
5257
});
5358
}
5459

@@ -67,18 +72,20 @@ class base {
6772
path += `&page=${page}&per_page=${perPage}`;
6873

6974
return new Promise((resolve, reject) => {
70-
request(`${this.url}${path}`, {
71-
json: true,
72-
insecure: this._insecure,
73-
proxy: this._proxy,
74-
resolveWithFullResponse: true,
75-
headers: {
76-
'PRIVATE-TOKEN': this.token
77-
}
78-
}).then(response => {
79-
if (this.config.get('_createDump')) this.setDump(response, key);
80-
resolve(response);
81-
}).catch(e => reject(e));
75+
throttle(() => {
76+
request(`${this.url}${path}`, {
77+
json: true,
78+
insecure: this._insecure,
79+
proxy: this._proxy,
80+
resolveWithFullResponse: true,
81+
headers: {
82+
'PRIVATE-TOKEN': this.token
83+
}
84+
}).then(response => {
85+
if (this.config.get('_createDump')) this.setDump(response, key);
86+
resolve(response);
87+
}).catch(e => reject(e));
88+
})
8289
});
8390
}
8491

0 commit comments

Comments
 (0)