forked from analog-nico/quota
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathechonest.js
40 lines (33 loc) · 897 Bytes
/
echonest.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
'use strict';
var Manager = require('../manager.js');
var _ = require('lodash');
/**
* Quota Preset for The Echonest
*
* Quota rules based on: http://developer.echonest.com/docs/v4#rate-limits
* The Echonest API docs: http://developer.echonest.com/docs/v4
*
* In a cluster environment a local Server cannot be used unless the limit is
* reduced (to 120 / number of node.js instances) so that an overall request
* rate that exceeds the limit is unlikely.
*
* @param options
* @returns {Manager}
*/
module.exports = function (options) {
_.defaults(options, {
limit: 120
});
var manager = new Manager({
backoff: 'timeout'
});
manager.addRule({
name: 'main',
limit: options.limit,
window: 60*1000,
throttling: 'window-sliding',
queueing: 'fifo',
resource: 'requests'
});
return manager;
};