-
Notifications
You must be signed in to change notification settings - Fork 84
Fix rate limit of 600 requests per minutes on Gitlab.com #106
Conversation
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.
cgdobre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution. It will be a great improvement!
src/models/base.js
Outdated
| const throttledQueue = require('throttled-queue'); | ||
|
|
||
| const throttle = throttledQueue(10, 1000); |
There was a problem hiding this comment.
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
| const throttledQueue = require('throttled-queue'); | |
| const throttle = throttledQueue(10, 1000); | |
| const throttledQueue = require('throttled-queue'); | |
| [...] | |
| let throttle = throttledQueue(this._throttle, 1000); | |
| [...] |
src/models/base.js
Outdated
| 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)); | ||
| }) |
There was a problem hiding this comment.
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
| 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)); | |
| })); |
src/models/base.js
Outdated
| 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)); | ||
| }) |
There was a problem hiding this comment.
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.
|
PS: also update and include the yarn.lock file because the CI job fails without it |
|
PS2: goes without saying, if you need any help with the changes, just ask. |
- whitepace magic to minimize diff - update yarn.lock file
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.