-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (45 loc) · 1.09 KB
/
index.js
File metadata and controls
56 lines (45 loc) · 1.09 KB
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
const _ = require('lodash');
const BullQueue = require('./bull');
const BeeQueue = require('./bee');
class Queues {
constructor(config) {
this._queues = {};
this.useCdn = {
value: true,
get useCdn() {
return this.value;
},
set useCdn(newValue) {
this.value = newValue;
}
};
this.setConfig(config);
}
list() {
return this._config.queues;
}
setConfig(config) {
this._config = config;
}
async get(queueName, queueHost) {
const queueConfig = _.find(this._config.queues, {
name: queueName,
hostId: queueHost
});
if (!queueConfig) return null;
if (this._queues[queueHost] && this._queues[queueHost][queueName]) {
return this._queues[queueHost][queueName];
}
const {type} = queueConfig;
let queue;
if (type === 'bee') {
queue = new BeeQueue(queueConfig);
} else {
queue = new BullQueue(queueConfig);
}
this._queues[queueHost] = this._queues[queueHost] || {};
this._queues[queueHost][queueName] = queue;
return queue;
}
}
module.exports = Queues;