Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
allow configuring git lab api throttle
  • Loading branch information
ndu2 committed May 24, 2025
commit 3c16d6bfcfa33d348a129b94f7a456fd6c44b95c
9 changes: 9 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ extend: true
# defaults to 10
_parallel: 20


# throttle API request to gitlab to max at throttleMaxRequestsPerInterval per throttleInterval (ms)
# defaults to 10
throttleMaxRequestsPerInterval: 10
# throttle API request to gitlab to max at throttleMaxRequestsPerInterval per throttleInterval (ms)
# defaults to 1000
throttleInterval: 1000


# Change rows per page (max. 100)
# defaults to 100
_perPage: 100
Expand Down
4 changes: 3 additions & 1 deletion src/include/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const defaults = {
_parallel: 10,
_verbose: false,
_checkToken: true,
_skipDescriptionParsing: false
_skipDescriptionParsing: false,
throttleMaxRequestsPerInterval: 10,
throttleInterval: 1000,
};

/**
Expand Down
18 changes: 13 additions & 5 deletions src/models/base.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import request from 'request-promise-native';
import url from 'url';
import async from 'async';
import crypto from 'crypto';
import throttleFactory from 'throttled-queue';
const throttle = throttleFactory(10, 1000);

/**
* base model
*/
class base {
static throttle;

static init(config) {
if(base.throttle == undefined){
base.throttle = throttleFactory(config.data.throttleMaxRequestsPerInterval, config.data.throttleInterval);
}
}


/**
* construct
* @param config
*/
constructor(config) {
base.init(config);
this.config = config;

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

data.private_token = this.token;

return new Promise((resolve, reject) => throttle(() => {
return new Promise((resolve, reject) => base.throttle(() => {
request.post(`${this.url}${path}`, {
json: true,
body: data,
Expand Down Expand Up @@ -68,7 +76,7 @@ class base {
let key = base.createDumpKey(path, data);
if (this.config.dump) return this.getDump(key);

return new Promise((resolve, reject) => throttle(() => {
return new Promise((resolve, reject) => base.throttle(() => {
request.post(`${path}`, {
json: true,
body: data,
Expand Down Expand Up @@ -101,7 +109,7 @@ class base {
path += (path.includes('?') ? '&' : '?') + `private_token=${this.token}`;
path += `&page=${page}&per_page=${perPage}`;

return new Promise((resolve, reject) => throttle(() => {
return new Promise((resolve, reject) => base.throttle(() => {
request(`${this.url}${path}`, {
json: true,
insecure: this._insecure,
Expand Down