Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
jedecaron committed Mar 9, 2020
commit f6f49da1403a06d93be1b02406b7c7a37898f0d9
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"request-promise-native": "^1.0.4",
"shelljs": "^0.8.3",
"tempfile": "^2.0.0",
"throttled-queue": "^1.0.7",
"underscore": "^1.9.1",
"xdg-basedir": "^3.0.0",
"xlsx": "^0.13.5"
Expand Down
57 changes: 32 additions & 25 deletions src/models/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const request = require('request-promise-native');
const url = require('url');
const async = require('async');
const crypto = require('crypto');
const throttledQueue = require('throttled-queue');

const throttle = throttledQueue(10, 1000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a way to configure requests per second, as it is done now for parallel. Of course, this means also that:

  • the declaration of throttle needs to be moved inside the base object.

  • the new throttle parameter needs to be added in the configuration

Suggested change
const throttledQueue = require('throttled-queue');
const throttle = throttledQueue(10, 1000);
const throttledQueue = require('throttled-queue');
[...]
let throttle = throttledQueue(this._throttle, 1000);
[...]


/**
* base model
Expand Down Expand Up @@ -36,19 +39,21 @@ class base {
data.private_token = this.token;

return new Promise((resolve, reject) => {
request.post(`${this.url}${path}`, {
json: true,
body: data,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
throttle(() => {
request.post(`${this.url}${path}`, {
json: true,
body: data,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move throttle() on line up to minimize the diff

Suggested change
throttle(() => {
request.post(`${this.url}${path}`, {
json: true,
body: data,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
})
return new Promise((resolve, reject) => throttle(() => {
request.post(`${this.url}${path}`, {
json: true,
body: data,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
}));

});
}

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

return new Promise((resolve, reject) => {
request(`${this.url}${path}`, {
json: true,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
throttle(() => {
request(`${this.url}${path}`, {
json: true,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same suggestion as above. Move throttle one line up and un-indent the request lines to minimize the diff.

});
}

Expand Down