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

Commit f377108

Browse files
jdecaronjedecaroncgdobre
authored
Fix rate limit of 600 requests per minutes on Gitlab.com (#106)
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. Co-authored-by: Jean-Denis Caron <[email protected]> Co-authored-by: Ciprian Dobre-Trifan <[email protected]>
1 parent c4692a5 commit f377108

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const request = require('request-promise-native');
22
const url = require('url');
33
const async = require('async');
44
const crypto = require('crypto');
5+
const throttle = require('throttled-queue')(10, 1000);
56

67
/**
78
* base model
@@ -35,7 +36,7 @@ class base {
3536

3637
data.private_token = this.token;
3738

38-
return new Promise((resolve, reject) => {
39+
return new Promise((resolve, reject) => throttle(() => {
3940
request.post(`${this.url}${path}`, {
4041
json: true,
4142
body: data,
@@ -49,7 +50,7 @@ class base {
4950
if (this.config.get('_createDump')) this.setDump(response, key);
5051
resolve(response);
5152
}).catch(e => reject(e));
52-
});
53+
}));
5354
}
5455

5556
/**
@@ -66,7 +67,7 @@ class base {
6667
path += (path.includes('?') ? '&' : '?') + `private_token=${this.token}`;
6768
path += `&page=${page}&per_page=${perPage}`;
6869

69-
return new Promise((resolve, reject) => {
70+
return new Promise((resolve, reject) => throttle(() => {
7071
request(`${this.url}${path}`, {
7172
json: true,
7273
insecure: this._insecure,
@@ -79,7 +80,7 @@ class base {
7980
if (this.config.get('_createDump')) this.setDump(response, key);
8081
resolve(response);
8182
}).catch(e => reject(e));
82-
});
83+
}));
8384
}
8485

8586
/**
@@ -190,4 +191,4 @@ class base {
190191
}
191192
}
192193

193-
module.exports = base;
194+
module.exports = base;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,11 @@ [email protected], text-encoding@^0.6.4:
24292429
version "0.6.4"
24302430
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
24312431

2432+
throttled-queue@^1.0.7:
2433+
version "1.0.7"
2434+
resolved "https://registry.yarnpkg.com/throttled-queue/-/throttled-queue-1.0.7.tgz#da7ed6702941993044a1c5fd2ac3a58582dd2977"
2435+
integrity sha512-/HT49S7m+NvdyJMoMRzIYlawKjeHn8jEc8TZaGmFi5IBu09hIiU/QoP1zcrB9X2qsVC11PgfRfqd8zEQs7PlEA==
2436+
24322437
throttleit@^1.0.0:
24332438
version "1.0.0"
24342439
resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-1.0.0.tgz#9e785836daf46743145a5984b6268d828528ac6c"

0 commit comments

Comments
 (0)