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

Commit c72b308

Browse files
author
Adrián Escoms
committed
fix:add throtle to avoid overrate the GitLab API
1 parent e059f1f commit c72b308

File tree

4 files changed

+35
-77
lines changed

4 files changed

+35
-77
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:8.2.1-alpine
22

3-
ENV GTT_VERSION 1.7.39
3+
ENV GTT_VERSION 1.7.40
44

55
RUN yarn global add --prefix /usr/local "gitlab-time-tracker@$GTT_VERSION"
66

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitlab-time-tracker",
3-
"version": "1.7.39",
3+
"version": "1.7.40",
44
"description": "A command line interface for GitLabs time tracking feature.",
55
"bugs": {
66
"url": "https://github.com/kriskbx/gitlab-time-tracker/issues"
@@ -53,10 +53,10 @@
5353
"progress": "^2.0.0",
5454
"prompt": "^1.0.0",
5555
"read-yaml": "^1.1.0",
56-
"request": "^2.87.0",
5756
"request-promise-native": "^1.0.4",
5857
"shelljs": "^0.8.3",
5958
"tempfile": "^2.0.0",
59+
"throttled-queue": "^1.0.7",
6060
"underscore": "^1.9.1",
6161
"xdg-basedir": "^3.0.0",
6262
"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, 10000, true);
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

yarn.lock

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,30 +2012,6 @@ request-promise-native@^1.0.4:
20122012
stealthy-require "^1.1.0"
20132013
tough-cookie ">=2.3.3"
20142014

2015-
2016-
version "2.79.0"
2017-
resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de"
2018-
dependencies:
2019-
aws-sign2 "~0.6.0"
2020-
aws4 "^1.2.1"
2021-
caseless "~0.11.0"
2022-
combined-stream "~1.0.5"
2023-
extend "~3.0.0"
2024-
forever-agent "~0.6.1"
2025-
form-data "~2.1.1"
2026-
har-validator "~2.0.6"
2027-
hawk "~3.1.3"
2028-
http-signature "~1.1.0"
2029-
is-typedarray "~1.0.0"
2030-
isstream "~0.1.2"
2031-
json-stringify-safe "~5.0.1"
2032-
mime-types "~2.1.7"
2033-
oauth-sign "~0.8.1"
2034-
qs "~6.3.0"
2035-
stringstream "~0.0.4"
2036-
tough-cookie "~2.3.0"
2037-
tunnel-agent "~0.4.1"
2038-
uuid "^3.0.0"
20392015

20402016
request@^2.81.0:
20412017
version "2.85.0"
@@ -2064,31 +2040,6 @@ request@^2.81.0:
20642040
tunnel-agent "^0.6.0"
20652041
uuid "^3.1.0"
20662042

2067-
request@^2.87.0:
2068-
version "2.87.0"
2069-
resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e"
2070-
dependencies:
2071-
aws-sign2 "~0.7.0"
2072-
aws4 "^1.6.0"
2073-
caseless "~0.12.0"
2074-
combined-stream "~1.0.5"
2075-
extend "~3.0.1"
2076-
forever-agent "~0.6.1"
2077-
form-data "~2.3.1"
2078-
har-validator "~5.0.3"
2079-
http-signature "~1.2.0"
2080-
is-typedarray "~1.0.0"
2081-
isstream "~0.1.2"
2082-
json-stringify-safe "~5.0.1"
2083-
mime-types "~2.1.17"
2084-
oauth-sign "~0.8.2"
2085-
performance-now "^2.1.0"
2086-
qs "~6.5.1"
2087-
safe-buffer "^5.1.1"
2088-
tough-cookie "~2.3.3"
2089-
tunnel-agent "^0.6.0"
2090-
uuid "^3.1.0"
2091-
20922043
request@~2.88.0:
20932044
version "2.88.0"
20942045
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"

0 commit comments

Comments
 (0)