keuss 2.1.0 → 2.2.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/Pipeline/Queue.js +10 -1
- package/Queue.js +2 -0
- package/backends/bucket-mongo-safe.js +2 -1
- package/backends/intraorder.js +2 -1
- package/backends/mongo.js +12 -2
- package/backends/pl-mongo.js +2 -1
- package/backends/postgres.js +16 -3
- package/backends/ps-mongo.js +12 -2
- package/backends/redis-list.js +2 -1
- package/backends/redis-oq.js +2 -1
- package/backends/stream-mongo.js +2 -1
- package/package.json +4 -4
- package/utils/RedisOrderedQueue.js +23 -3
package/Pipeline/Queue.js
CHANGED
|
@@ -37,7 +37,16 @@ class PipelinedMongoQueue extends Queue {
|
|
|
37
37
|
|
|
38
38
|
this._col.insertOne (entry, {})
|
|
39
39
|
.then (res => cb (null, res.insertedId))
|
|
40
|
-
.catch (
|
|
40
|
+
.catch (err => {
|
|
41
|
+
if (err.code == 11000) {
|
|
42
|
+
const e = new Error (`duplicated entry with _id ${entry._id}`)
|
|
43
|
+
e.code = 'EDUP';
|
|
44
|
+
cb(e)
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
cb (err)
|
|
48
|
+
}
|
|
49
|
+
});
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
|
package/Queue.js
CHANGED
package/backends/intraorder.js
CHANGED
package/backends/mongo.js
CHANGED
|
@@ -37,7 +37,16 @@ class SimpleMongoQueue extends Queue {
|
|
|
37
37
|
debug ('inserted entry %j -> %j', entry, res)
|
|
38
38
|
cb (null, res.insertedId);
|
|
39
39
|
})
|
|
40
|
-
.catch (
|
|
40
|
+
.catch (err => {
|
|
41
|
+
if (err.code == 11000) {
|
|
42
|
+
const e = new Error (`duplicated entry with _id ${entry._id}`)
|
|
43
|
+
e.code = 'EDUP';
|
|
44
|
+
cb(e)
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
cb (err)
|
|
48
|
+
}
|
|
49
|
+
});
|
|
41
50
|
}
|
|
42
51
|
c
|
|
43
52
|
|
|
@@ -302,7 +311,8 @@ class Factory extends QFactory_MongoDB_defaults {
|
|
|
302
311
|
reserve: true,
|
|
303
312
|
pipeline: false,
|
|
304
313
|
tape: false,
|
|
305
|
-
remove: true
|
|
314
|
+
remove: true,
|
|
315
|
+
id: true,
|
|
306
316
|
};
|
|
307
317
|
}
|
|
308
318
|
}
|
package/backends/pl-mongo.js
CHANGED
package/backends/postgres.js
CHANGED
|
@@ -58,7 +58,7 @@ class PGQueue extends Queue {
|
|
|
58
58
|
/////////////////////////////////////////
|
|
59
59
|
// add element to queue
|
|
60
60
|
insert (entry, cb) {
|
|
61
|
-
const _id = entry.
|
|
61
|
+
const _id = entry._id || uuid.v4();
|
|
62
62
|
const tries = entry.tries || 0;
|
|
63
63
|
const mature = new Date (entry.mature);
|
|
64
64
|
|
|
@@ -73,7 +73,19 @@ class PGQueue extends Queue {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
this._pool.query (`INSERT INTO ${this._tbl_name} VALUES($1, $2, $3, $4)`, [_id, pl, mature, tries], (err, res) => {
|
|
76
|
-
if (err)
|
|
76
|
+
if (err) {
|
|
77
|
+
if (err.code == '23505') {
|
|
78
|
+
const e = new Error (`duplicated entry with _id ${entry._id}`)
|
|
79
|
+
e.code = 'EDUP';
|
|
80
|
+
cb(e)
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
cb (err)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
77
89
|
cb (null, _id)
|
|
78
90
|
})
|
|
79
91
|
}
|
|
@@ -353,7 +365,8 @@ class Factory extends QFactory {
|
|
|
353
365
|
reserve: true,
|
|
354
366
|
pipeline: false,
|
|
355
367
|
tape: false,
|
|
356
|
-
remove: true
|
|
368
|
+
remove: true,
|
|
369
|
+
id: true,
|
|
357
370
|
};
|
|
358
371
|
}
|
|
359
372
|
}
|
package/backends/ps-mongo.js
CHANGED
|
@@ -35,7 +35,16 @@ class PersistentMongoQueue extends Queue {
|
|
|
35
35
|
insert (entry, cb) {
|
|
36
36
|
this._col.insertOne (entry, {})
|
|
37
37
|
.then (res => cb (null, res.insertedId))
|
|
38
|
-
.catch (
|
|
38
|
+
.catch (err => {
|
|
39
|
+
if (err.code == 11000) {
|
|
40
|
+
const e = new Error (`duplicated entry with _id ${entry._id}`)
|
|
41
|
+
e.code = 'EDUP';
|
|
42
|
+
cb(e)
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
cb (err)
|
|
46
|
+
}
|
|
47
|
+
});
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
|
|
@@ -332,7 +341,8 @@ class Factory extends QFactory_MongoDB_defaults {
|
|
|
332
341
|
reserve: true,
|
|
333
342
|
pipeline: false,
|
|
334
343
|
tape: true,
|
|
335
|
-
remove: true
|
|
344
|
+
remove: true,
|
|
345
|
+
id: true,
|
|
336
346
|
};
|
|
337
347
|
}
|
|
338
348
|
}
|
package/backends/redis-list.js
CHANGED
package/backends/redis-oq.js
CHANGED
package/backends/stream-mongo.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keuss",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"queue",
|
|
6
6
|
"persistent",
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
"pg": "~8.12.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"chance": "~1.1.
|
|
43
|
-
"mocha": "~11.7.
|
|
42
|
+
"chance": "~1.1.13",
|
|
43
|
+
"mocha": "~11.7.5",
|
|
44
44
|
"should": "~13.2.3",
|
|
45
45
|
"nyc": "~17.1.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
|
-
"test": "docker compose up -d; sleep 5; mocha --
|
|
48
|
+
"test": "docker compose up -d; sleep 5; mocha --reporter spec --check-leaks --no-timeouts --exit test/ ; docker compose down",
|
|
49
49
|
"test-with-coverage": "docker compose up -d; sleep 5; nyc --reporter=html -- mocha --reporter spec --check-leaks --no-timeouts --exit ; test/docker compose down"
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -7,6 +7,13 @@ const _s_lua_code_push = `
|
|
|
7
7
|
-- mature-t in ARGV[2]
|
|
8
8
|
-- val in ARGV[3]
|
|
9
9
|
|
|
10
|
+
-- check id exists
|
|
11
|
+
local exists = redis.call ('HGET', 'keuss:q:ordered_queue:hash:' .. KEYS[1], ARGV[1])
|
|
12
|
+
|
|
13
|
+
if (exists) then
|
|
14
|
+
return redis.error_reply('EDUP duplicated _id ' .. ARGV[1])
|
|
15
|
+
end
|
|
16
|
+
|
|
10
17
|
-- insert obj in hash by id
|
|
11
18
|
redis.call ('HSET', 'keuss:q:ordered_queue:hash:' .. KEYS[1], ARGV[1], ARGV[3])
|
|
12
19
|
|
|
@@ -174,20 +181,33 @@ class RedisOrderedQueue {
|
|
|
174
181
|
push (entry, done) {
|
|
175
182
|
//////////////////////////////////
|
|
176
183
|
var pl = {
|
|
177
|
-
_id: entry.
|
|
184
|
+
_id: entry._id || uuid.v4(),
|
|
178
185
|
payload: entry.payload,
|
|
179
186
|
tries: entry.tries,
|
|
180
187
|
hdrs: entry.hdrs || {},
|
|
181
188
|
mature: (entry.mature || new Date ()).getTime ()
|
|
182
189
|
};
|
|
183
190
|
|
|
184
|
-
|
|
185
191
|
if (Buffer.isBuffer (pl.payload)) {
|
|
186
192
|
pl.payload = pl.payload.toString ('base64');
|
|
187
193
|
pl.type = 'buffer';
|
|
188
194
|
}
|
|
189
195
|
|
|
190
|
-
this._rediscl.roq_push (this._name, pl._id, pl.mature, JSON.stringify (pl),
|
|
196
|
+
this._rediscl.roq_push (this._name, pl._id, pl.mature, JSON.stringify (pl), (err, res) => {
|
|
197
|
+
if (err) {
|
|
198
|
+
if (err.message.startsWith ('EDUP ')) {
|
|
199
|
+
const e = new Error (`duplicated entry with _id ${pl._id}`)
|
|
200
|
+
e.code = 'EDUP';
|
|
201
|
+
done(e);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
done (err)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
done (null, res);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
191
211
|
}
|
|
192
212
|
|
|
193
213
|
|