Skip to content

Commit 3c16d6b

Browse files
committed
allow configuring git lab api throttle
1 parent 84ffefb commit 3c16d6b

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

documentation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,15 @@ extend: true
634634
# defaults to 10
635635
_parallel: 20
636636

637+
638+
# throttle API request to gitlab to max at throttleMaxRequestsPerInterval per throttleInterval (ms)
639+
# defaults to 10
640+
throttleMaxRequestsPerInterval: 10
641+
# throttle API request to gitlab to max at throttleMaxRequestsPerInterval per throttleInterval (ms)
642+
# defaults to 1000
643+
throttleInterval: 1000
644+
645+
637646
# Change rows per page (max. 100)
638647
# defaults to 100
639648
_perPage: 100

src/include/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ const defaults = {
4343
_parallel: 10,
4444
_verbose: false,
4545
_checkToken: true,
46-
_skipDescriptionParsing: false
46+
_skipDescriptionParsing: false,
47+
throttleMaxRequestsPerInterval: 10,
48+
throttleInterval: 1000,
4749
};
4850

4951
/**

src/models/base.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
import request from 'request-promise-native';
2-
import url from 'url';
32
import async from 'async';
43
import crypto from 'crypto';
54
import throttleFactory from 'throttled-queue';
6-
const throttle = throttleFactory(10, 1000);
75

86
/**
97
* base model
108
*/
119
class base {
10+
static throttle;
11+
12+
static init(config) {
13+
if(base.throttle == undefined){
14+
base.throttle = throttleFactory(config.data.throttleMaxRequestsPerInterval, config.data.throttleInterval);
15+
}
16+
}
17+
18+
1219
/**
1320
* construct
1421
* @param config
1522
*/
1623
constructor(config) {
24+
base.init(config);
1725
this.config = config;
1826

1927
this.url = config.get('url').endsWith('/') ? config.get('url') : `${config.get('url')}/`;
@@ -37,7 +45,7 @@ class base {
3745

3846
data.private_token = this.token;
3947

40-
return new Promise((resolve, reject) => throttle(() => {
48+
return new Promise((resolve, reject) => base.throttle(() => {
4149
request.post(`${this.url}${path}`, {
4250
json: true,
4351
body: data,
@@ -68,7 +76,7 @@ class base {
6876
let key = base.createDumpKey(path, data);
6977
if (this.config.dump) return this.getDump(key);
7078

71-
return new Promise((resolve, reject) => throttle(() => {
79+
return new Promise((resolve, reject) => base.throttle(() => {
7280
request.post(`${path}`, {
7381
json: true,
7482
body: data,
@@ -101,7 +109,7 @@ class base {
101109
path += (path.includes('?') ? '&' : '?') + `private_token=${this.token}`;
102110
path += `&page=${page}&per_page=${perPage}`;
103111

104-
return new Promise((resolve, reject) => throttle(() => {
112+
return new Promise((resolve, reject) => base.throttle(() => {
105113
request(`${this.url}${path}`, {
106114
json: true,
107115
insecure: this._insecure,

0 commit comments

Comments
 (0)