keuss 2.0.6 → 2.1.0
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/.mocharc.yaml +3 -0
- package/CHANGELOG.md +1 -1
- package/Pipeline/BaseLink.js +1 -1
- package/Pipeline/Queue.js +106 -90
- package/Queue.js +13 -2
- package/README.md +4 -4
- package/backends/bucket-mongo-safe.js +164 -144
- package/backends/intraorder.js +92 -82
- package/backends/mongo.js +137 -95
- package/backends/pl-mongo.js +18 -30
- package/backends/ps-mongo.js +121 -110
- package/backends/redis-oq.js +0 -2
- package/backends/stream-mongo.js +81 -63
- package/lib/mubsub/channel.js +313 -0
- package/lib/mubsub/connection.js +79 -0
- package/lib/mubsub/index.js +10 -0
- package/package.json +8 -10
- package/signal/mongo-capped.js +1 -1
- package/stats/mongo.js +91 -54
package/.mocharc.yaml
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
-
Changelog is now part of the official Keuss documentation, find it [here](https://pepmartinez.
|
|
2
|
+
Changelog is now part of the official Keuss documentation, find it [here](https://pepmartinez.codeberg.page/keuss//docs/changelog)
|
package/Pipeline/BaseLink.js
CHANGED
|
@@ -55,6 +55,7 @@ class BaseLink extends EventEmitter {
|
|
|
55
55
|
/////////////////////////////////////////
|
|
56
56
|
stop () {
|
|
57
57
|
this._src.cancel ();
|
|
58
|
+
debug ('%s: stopped', this._name);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
|
|
@@ -164,7 +165,6 @@ class BaseLink extends EventEmitter {
|
|
|
164
165
|
}
|
|
165
166
|
catch (e) {
|
|
166
167
|
debug ('catch error, emitting it: ', e);
|
|
167
|
-
console.log ('catch error, emitting it: ', e);
|
|
168
168
|
this.emit (e);
|
|
169
169
|
this._on_error (e, elem, ondata);
|
|
170
170
|
}
|
package/Pipeline/Queue.js
CHANGED
|
@@ -32,125 +32,133 @@ class PipelinedMongoQueue extends Queue {
|
|
|
32
32
|
|
|
33
33
|
/////////////////////////////////////////
|
|
34
34
|
// add element to queue
|
|
35
|
-
insert (entry,
|
|
35
|
+
insert (entry, cb) {
|
|
36
36
|
entry._q = this._name;
|
|
37
37
|
|
|
38
|
-
this._col.insertOne (entry, {}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
38
|
+
this._col.insertOne (entry, {})
|
|
39
|
+
.then (res => cb (null, res.insertedId))
|
|
40
|
+
.catch (cb);
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
|
|
45
44
|
/////////////////////////////////////////
|
|
46
45
|
// get element from queue
|
|
47
|
-
get (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
get (cb) {
|
|
47
|
+
const query = {
|
|
48
|
+
_q: this._name,
|
|
49
|
+
mature: {$lte: Queue.nowPlusSecs (0)}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const opts = {
|
|
53
|
+
sort: {mature : 1},
|
|
54
|
+
includeResultMetadata: true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this._col.findOneAndDelete (query, opts)
|
|
58
|
+
.then (res => {
|
|
59
|
+
const v = res && res.value;
|
|
60
|
+
if (!v) return cb ();
|
|
52
61
|
if (v.payload._bsontype == 'Binary') v.payload = v.payload.buffer;
|
|
53
|
-
|
|
54
|
-
})
|
|
62
|
+
cb (null, v);
|
|
63
|
+
})
|
|
64
|
+
.catch (cb);
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
|
|
58
68
|
//////////////////////////////////
|
|
59
69
|
// reserve element: call cb (err, pl) where pl has an id
|
|
60
|
-
reserve (
|
|
61
|
-
|
|
70
|
+
reserve (cb) {
|
|
71
|
+
const delay = this._opts.reserve_delay || 120;
|
|
62
72
|
|
|
63
|
-
|
|
73
|
+
const query = {
|
|
64
74
|
_q: this._name,
|
|
65
75
|
mature: {$lte: Queue.nowPlusSecs (0)}
|
|
66
76
|
};
|
|
67
77
|
|
|
68
|
-
|
|
78
|
+
const update = {
|
|
69
79
|
$set: {mature: Queue.nowPlusSecs (delay), reserved: new Date ()},
|
|
70
80
|
$inc: {tries: 1}
|
|
71
81
|
};
|
|
72
82
|
|
|
73
|
-
|
|
83
|
+
const opts = {
|
|
74
84
|
sort: {mature : 1},
|
|
75
|
-
returnDocument: 'before'
|
|
85
|
+
returnDocument: 'before',
|
|
86
|
+
includeResultMetadata: true
|
|
76
87
|
};
|
|
77
88
|
|
|
78
|
-
this._col.findOneAndUpdate (query, update, opts
|
|
79
|
-
|
|
80
|
-
const v =
|
|
81
|
-
if (!v) return
|
|
89
|
+
this._col.findOneAndUpdate (query, update, opts)
|
|
90
|
+
.then (res => {
|
|
91
|
+
const v = res && res.value;
|
|
92
|
+
if (!v) return cb ();
|
|
82
93
|
if (v.payload._bsontype == 'Binary') v.payload = v.payload.buffer;
|
|
83
|
-
|
|
84
|
-
})
|
|
94
|
+
cb (null, v);
|
|
95
|
+
})
|
|
96
|
+
.catch (cb);
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
|
|
88
100
|
//////////////////////////////////
|
|
89
101
|
// commit previous reserve, by p.id
|
|
90
|
-
commit (id,
|
|
91
|
-
|
|
102
|
+
commit (id, cb) {
|
|
103
|
+
const query = {
|
|
104
|
+
_q: this._name,
|
|
105
|
+
reserved: {$exists: true}
|
|
106
|
+
}
|
|
92
107
|
|
|
93
108
|
try {
|
|
94
|
-
query =
|
|
95
|
-
_id: (_.isString(id) ? new mongo.ObjectID (id) : id),
|
|
96
|
-
_q: this._name,
|
|
97
|
-
reserved: {$exists: true}
|
|
98
|
-
};
|
|
109
|
+
query._id = (_.isString(id) ? new mongo.ObjectId (id) : id);
|
|
99
110
|
}
|
|
100
111
|
catch (e) {
|
|
101
|
-
return
|
|
112
|
+
return cb ('id [' + id + '] can not be used as rollback id: ' + e);
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
this._col.deleteOne (query, {}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
115
|
+
this._col.deleteOne (query, {})
|
|
116
|
+
.then (res => cb (null, res && (res.deletedCount == 1)))
|
|
117
|
+
.catch (cb);
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
|
|
111
121
|
//////////////////////////////////
|
|
112
122
|
// rollback previous reserve, by p.id
|
|
113
|
-
rollback (id, next_t,
|
|
123
|
+
rollback (id, next_t, cb) {
|
|
114
124
|
if (_.isFunction (next_t)) {
|
|
115
|
-
|
|
125
|
+
cb = next_t;
|
|
116
126
|
next_t = null;
|
|
117
127
|
}
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
const query = {
|
|
130
|
+
_q: this._name,
|
|
131
|
+
reserved: {$exists: true}
|
|
132
|
+
}
|
|
120
133
|
|
|
121
134
|
try {
|
|
122
|
-
query =
|
|
123
|
-
_id: (_.isString(id) ? new mongo.ObjectID (id) : id),
|
|
124
|
-
_q: this._name,
|
|
125
|
-
reserved: {$exists: true}
|
|
126
|
-
};
|
|
135
|
+
query._id = (_.isString(id) ? new mongo.ObjectId (id) : id);
|
|
127
136
|
}
|
|
128
137
|
catch (e) {
|
|
129
|
-
return
|
|
138
|
+
return cb ('id [' + id + '] can not be used as rollback id: ' + e);
|
|
130
139
|
}
|
|
131
140
|
|
|
132
|
-
|
|
141
|
+
const update = {
|
|
133
142
|
$set: {mature: (next_t ? new Date (next_t) : Queue.now ())},
|
|
134
143
|
$unset: {reserved: ''}
|
|
135
144
|
};
|
|
136
145
|
|
|
137
|
-
this._col.updateOne (query, update, {}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
146
|
+
this._col.updateOne (query, update, {})
|
|
147
|
+
.then (res => cb (null, res && (res.modifiedCount == 1)))
|
|
148
|
+
.catch (cb);
|
|
141
149
|
}
|
|
142
150
|
|
|
143
151
|
|
|
144
152
|
//////////////////////////////////
|
|
145
153
|
// passes element to the next queue in pipeline
|
|
146
|
-
pl_step (id, next_queue, opts,
|
|
147
|
-
|
|
154
|
+
pl_step (id, next_queue, opts, cb) {
|
|
155
|
+
const q = {
|
|
148
156
|
_id: id,
|
|
149
157
|
_q: this._name,
|
|
150
158
|
reserved: {$exists: true}
|
|
151
159
|
};
|
|
152
160
|
|
|
153
|
-
|
|
161
|
+
const upd = {
|
|
154
162
|
$set: {
|
|
155
163
|
mature: opts.mature || Queue.now (),
|
|
156
164
|
tries: opts.tries || 0,
|
|
@@ -170,93 +178,101 @@ class PipelinedMongoQueue extends Queue {
|
|
|
170
178
|
_.each (opts.hdrs, (v, k) => upd.$set['hdrs.' + k] = v);
|
|
171
179
|
}
|
|
172
180
|
|
|
173
|
-
this._col.updateOne (q, upd, {}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
});
|
|
181
|
+
this._col.updateOne (q, upd, {})
|
|
182
|
+
.then (res => cb (null, res && (res.modifiedCount == 1)))
|
|
183
|
+
.catch (cb);
|
|
177
184
|
}
|
|
178
185
|
|
|
179
186
|
|
|
180
187
|
//////////////////////////////////
|
|
181
188
|
// queue size including non-mature elements
|
|
182
|
-
totalSize (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
this._col.countDocuments (q, opts
|
|
189
|
+
totalSize (cb) {
|
|
190
|
+
const q = {_q: this._name};
|
|
191
|
+
const opts = {};
|
|
192
|
+
this._col.countDocuments (q, opts)
|
|
193
|
+
.then (res => cb (null, res))
|
|
194
|
+
.catch (cb);
|
|
186
195
|
}
|
|
187
196
|
|
|
188
197
|
|
|
189
198
|
//////////////////////////////////
|
|
190
199
|
// queue size NOT including non-mature elements
|
|
191
|
-
size (
|
|
192
|
-
|
|
200
|
+
size (cb) {
|
|
201
|
+
const q = {
|
|
193
202
|
_q: this._name,
|
|
194
203
|
mature : {$lte : Queue.now ()}
|
|
195
204
|
};
|
|
196
205
|
|
|
197
|
-
|
|
198
|
-
this._col.countDocuments (q, opts
|
|
206
|
+
const opts = {};
|
|
207
|
+
this._col.countDocuments (q, opts)
|
|
208
|
+
.then (res => cb (null, res))
|
|
209
|
+
.catch (cb);
|
|
199
210
|
}
|
|
200
211
|
|
|
201
212
|
|
|
202
213
|
//////////////////////////////////
|
|
203
214
|
// queue size of non-mature elements only
|
|
204
|
-
schedSize (
|
|
205
|
-
|
|
215
|
+
schedSize (cb) {
|
|
216
|
+
const q = {
|
|
206
217
|
_q: this._name,
|
|
207
218
|
mature : {$gt : Queue.now ()},
|
|
208
219
|
reserved: {$exists: false}
|
|
209
220
|
};
|
|
210
221
|
|
|
211
|
-
|
|
212
|
-
this._col.countDocuments (q, opts
|
|
222
|
+
const opts = {};
|
|
223
|
+
this._col.countDocuments (q, opts)
|
|
224
|
+
.then (res => cb (null, res))
|
|
225
|
+
.catch (cb);
|
|
213
226
|
}
|
|
214
227
|
|
|
215
228
|
|
|
216
229
|
//////////////////////////////////
|
|
217
230
|
// queue size of reserved elements only
|
|
218
|
-
resvSize (
|
|
219
|
-
|
|
231
|
+
resvSize (cb) {
|
|
232
|
+
const q = {
|
|
220
233
|
_q: this._name,
|
|
221
234
|
mature : {$gt : Queue.now ()},
|
|
222
235
|
reserved: {$exists: true}
|
|
223
236
|
};
|
|
224
237
|
|
|
225
|
-
|
|
226
|
-
this._col.countDocuments (q, opts
|
|
238
|
+
const opts = {};
|
|
239
|
+
this._col.countDocuments (q, opts)
|
|
240
|
+
.then (res => cb (null, res))
|
|
241
|
+
.catch (cb);
|
|
227
242
|
}
|
|
228
243
|
|
|
229
244
|
|
|
230
245
|
/////////////////////////////////////////
|
|
231
246
|
// get element from queue
|
|
232
|
-
next_t (
|
|
233
|
-
this._col.find ({_q: this._name})
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
})
|
|
247
|
+
next_t (cb) {
|
|
248
|
+
this._col.find ({_q: this._name})
|
|
249
|
+
.limit(1)
|
|
250
|
+
.sort ({mature:1})
|
|
251
|
+
.project ({mature:1})
|
|
252
|
+
.next ()
|
|
253
|
+
.then (res => cb (null, res && res.mature))
|
|
254
|
+
.catch (cb);
|
|
237
255
|
}
|
|
238
256
|
|
|
239
257
|
|
|
240
258
|
//////////////////////////////////////////////
|
|
241
259
|
// remove by id
|
|
242
|
-
remove (id,
|
|
243
|
-
|
|
260
|
+
remove (id, cb) {
|
|
261
|
+
const query = {
|
|
262
|
+
_q: this._name,
|
|
263
|
+
reserved: {$exists: false}
|
|
264
|
+
}
|
|
244
265
|
|
|
245
266
|
try {
|
|
246
|
-
query =
|
|
247
|
-
_id: (_.isString(id) ? new mongo.ObjectID (id) : id),
|
|
248
|
-
_q: this._name,
|
|
249
|
-
reserved: {$exists: false}
|
|
250
|
-
};
|
|
267
|
+
query._id = (_.isString(id) ? new mongo.ObjectId (id) : id);
|
|
251
268
|
}
|
|
252
269
|
catch (e) {
|
|
253
|
-
return
|
|
270
|
+
return cb ('id [' + id + '] can not be used as remove id: ' + e);
|
|
254
271
|
}
|
|
255
272
|
|
|
256
|
-
this._col.deleteOne (query, {}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
});
|
|
273
|
+
this._col.deleteOne (query, {})
|
|
274
|
+
.then (res => cb (null, res && (res.deletedCount == 1)))
|
|
275
|
+
.catch (cb);
|
|
260
276
|
}
|
|
261
277
|
|
|
262
278
|
|
package/Queue.js
CHANGED
|
@@ -489,9 +489,9 @@ class Queue {
|
|
|
489
489
|
//////////////////////////////////
|
|
490
490
|
// cancel a waiting consumer
|
|
491
491
|
cancel (tid) {
|
|
492
|
-
debug ('%s: cancelling tid %s', this._name, tid);
|
|
493
|
-
|
|
494
492
|
if (tid) {
|
|
493
|
+
debug ('%s: cancelling tid %s', this._name, tid);
|
|
494
|
+
|
|
495
495
|
let consumer_data = this._consumers_by_tid.get (tid);
|
|
496
496
|
|
|
497
497
|
if (!consumer_data) {
|
|
@@ -535,18 +535,27 @@ class Queue {
|
|
|
535
535
|
|
|
536
536
|
debug ('%s: cancelling tid %s (cid %s): callback called and removed', this._name, tid, consumer_data.cid);
|
|
537
537
|
}
|
|
538
|
+
else {
|
|
539
|
+
debug ('%s: cancelling tid %s (cid %s): has no callback!', this._name, tid);
|
|
540
|
+
}
|
|
538
541
|
|
|
539
542
|
if (consumer_data.cleanup_timeout) {
|
|
540
543
|
clearTimeout (consumer_data.cleanup_timeout);
|
|
541
544
|
consumer_data.cleanup_timeout = null;
|
|
542
545
|
debug ('%s: cancelling tid %s (cid %s): cleanup timeout removed', this._name, tid, consumer_data.cid);
|
|
543
546
|
}
|
|
547
|
+
else {
|
|
548
|
+
debug ('%s: cancelling tid %s (cid %s): has no cleanup timeout!', this._name, tid);
|
|
549
|
+
}
|
|
544
550
|
|
|
545
551
|
if (consumer_data.wakeup_timeout) {
|
|
546
552
|
clearTimeout (consumer_data.wakeup_timeout);
|
|
547
553
|
consumer_data.wakeup_timeout = null;
|
|
548
554
|
debug ('%s: cancelling tid %s (cid %s): wakeup timeout removed', this._name, tid, consumer_data.cid);
|
|
549
555
|
}
|
|
556
|
+
else {
|
|
557
|
+
debug ('%s: cancelling tid %s (cid %s): has no wakeup timeout!', this._name, tid);
|
|
558
|
+
}
|
|
550
559
|
|
|
551
560
|
debug ('%s: cancelling tid %s (cid %s): end', this._name, tid, consumer_data.cid);
|
|
552
561
|
});
|
|
@@ -654,9 +663,11 @@ class Queue {
|
|
|
654
663
|
};
|
|
655
664
|
|
|
656
665
|
if (consumer.reserve) {
|
|
666
|
+
debug ('%s - tid %s: calling getOrReserve_cb with reserve', this._name, consumer.tid);
|
|
657
667
|
this.reserve (getOrReserve_cb);
|
|
658
668
|
}
|
|
659
669
|
else {
|
|
670
|
+
debug ('%s - tid %s: calling getOrReserve_cb with get', this._name, consumer.tid);
|
|
660
671
|
this.get (getOrReserve_cb);
|
|
661
672
|
}
|
|
662
673
|
}
|
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Enterprise-grade Job Queues for node.js backed by redis, MongoDB or PostgreSQL
|
|
4
4
|
|
|
5
|
-
* [Quickstart](https://pepmartinez.
|
|
6
|
-
* [Documentation](https://pepmartinez.
|
|
7
|
-
* [Examples](https://pepmartinez.
|
|
8
|
-
* [Changelog](https://pepmartinez.
|
|
5
|
+
* [Quickstart](https://pepmartinez.codeberg.page/keuss/docs/quickstart)
|
|
6
|
+
* [Documentation](https://pepmartinez.codeberg.page/keuss/docs/)
|
|
7
|
+
* [Examples](https://pepmartinez.codeberg.page/keuss/docs/examples)
|
|
8
|
+
* [Changelog](https://pepmartinez.codeberg.page/keuss/docs/changelog)
|
|
9
9
|
|