-
Notifications
You must be signed in to change notification settings - Fork 7
/
github.js
60 lines (46 loc) · 1.24 KB
/
github.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
var Manager = require('../manager.js');
var _ = require('lodash');
/**
* Quota Preset for GitHub
*
* Quota rules based on: https://developer.github.com/v3/#rate-limiting
* GitHub API docs: https://developer.github.com/v3/
*
* In a cluster environment a local Server can be used if all requests are done
* on behalf of a user (authenticated requests) and request for a particular
* user are always done by the same node.js instance.
*
* @param options
* @returns {Manager}
*/
module.exports = function (options) {
_.defaults(options, {
authenticated: true,
forSearchAPI: false
});
var manager = new Manager({
backoff: 'timeout'
});
var ruleOptions = {
throttling: 'window-sliding',
queueing: 'fifo',
resource: 'requests'
};
if (options.authenticated) {
ruleOptions.scope = 'userId';
}
if (options.forSearchAPI) {
_.assign(ruleOptions, {
limit: options.authenticated ? 30 : 10,
window: 60*1000
});
} else {
_.assign(ruleOptions, {
limit: options.authenticated ? 5000 : 60,
window: 60*60*1000
});
}
manager.addRule(ruleOptions);
return manager;
};