keuss 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QFactory.js +38 -11
- package/package.json +1 -1
package/QFactory.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const async = require ('async');
|
|
2
|
+
const _ = require ('lodash');
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const LocalSignal = require ('./signal/local');
|
|
5
|
+
const MemStats = require ('./stats/mem');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const debug = require('debug')('keuss:QFactory');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
10
11
|
class QFactory {
|
|
11
12
|
constructor (opts) {
|
|
12
13
|
this._opts = opts || {};
|
|
@@ -15,6 +16,8 @@ class QFactory {
|
|
|
15
16
|
debug ('created QFactory %s with opts %o', this._name, this._opts);
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
|
|
20
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
18
21
|
async_init (cb) {
|
|
19
22
|
if (!this._opts.stats) this._opts.stats = {};
|
|
20
23
|
if (!this._opts.stats.opts) this._opts.stats.opts = {};
|
|
@@ -22,8 +25,8 @@ class QFactory {
|
|
|
22
25
|
if (!this._opts.signaller) this._opts.signaller = {};
|
|
23
26
|
if (!this._opts.signaller.opts) this._opts.signaller.opts = {};
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
const signal_provider = this._opts.signaller.provider || LocalSignal;
|
|
29
|
+
const stats_provider = this._opts.stats.provider || MemStats;
|
|
27
30
|
|
|
28
31
|
async.parallel ([
|
|
29
32
|
cb => signal_provider (this._opts.signaller.opts, cb),
|
|
@@ -50,18 +53,26 @@ class QFactory {
|
|
|
50
53
|
});
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
|
|
57
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
53
58
|
signaller_factory () {
|
|
54
59
|
return this._signaller_factory;
|
|
55
60
|
}
|
|
56
61
|
|
|
62
|
+
|
|
63
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
57
64
|
stats_factory () {
|
|
58
65
|
return this._stats_factory;
|
|
59
66
|
}
|
|
60
67
|
|
|
68
|
+
|
|
69
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
61
70
|
queue (name, opts, cb) {
|
|
62
71
|
return cb ();
|
|
63
72
|
}
|
|
64
73
|
|
|
74
|
+
|
|
75
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
65
76
|
close (cb) {
|
|
66
77
|
debug ('%s: closing', this._name);
|
|
67
78
|
async.parallel ([
|
|
@@ -70,50 +81,66 @@ class QFactory {
|
|
|
70
81
|
], cb);
|
|
71
82
|
}
|
|
72
83
|
|
|
84
|
+
|
|
85
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
73
86
|
name () {
|
|
74
87
|
return this._name;
|
|
75
88
|
}
|
|
76
89
|
|
|
90
|
+
|
|
91
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
77
92
|
type () {
|
|
78
93
|
return 'none';
|
|
79
94
|
}
|
|
80
95
|
|
|
96
|
+
|
|
97
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
81
98
|
capabilities () {
|
|
82
99
|
return {};
|
|
83
100
|
}
|
|
84
101
|
|
|
102
|
+
|
|
103
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
85
104
|
deadletter_queue () {
|
|
86
105
|
return this._deadletter_queue;
|
|
87
106
|
}
|
|
88
107
|
|
|
108
|
+
|
|
109
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
89
110
|
max_ko () {
|
|
90
111
|
return this._max_ko;
|
|
91
112
|
}
|
|
92
113
|
|
|
114
|
+
|
|
115
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
93
116
|
list (opts, cb) {
|
|
94
117
|
// use stats factory
|
|
95
118
|
this._stats_factory.queues (this.name (), opts, cb);
|
|
96
119
|
}
|
|
97
120
|
|
|
121
|
+
|
|
122
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
98
123
|
recreate_topology (cb) {
|
|
99
124
|
debug ('%s: recreating topology', this._name);
|
|
100
125
|
|
|
101
126
|
this.list ({full: true}, (err, ql) => {
|
|
102
127
|
if (err) return cb (err);
|
|
103
128
|
|
|
104
|
-
|
|
129
|
+
const tasks = {};
|
|
105
130
|
|
|
106
131
|
_.each (ql, (v, k) => {
|
|
107
132
|
debug ('%s: recreating topology: adding queue %s with opts %o', this._name, k, v.opts);
|
|
108
|
-
ret[k] = this.queue (k, v.opts);
|
|
133
|
+
ret[k] = cb => this.queue (k, v.opts, cb); // TODO fix to async
|
|
109
134
|
});
|
|
110
135
|
|
|
111
|
-
|
|
136
|
+
async.parallel (tasks, cb);
|
|
112
137
|
});
|
|
113
138
|
}
|
|
114
139
|
|
|
140
|
+
|
|
141
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
115
142
|
to_descriptor_obj () {
|
|
116
|
-
|
|
143
|
+
const obj = {
|
|
117
144
|
name: this.name (),
|
|
118
145
|
type: this.type (),
|
|
119
146
|
opts: _.omit (this._opts, ['stats', 'signaller']),
|