keuss 1.7.4 → 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/Pipeline/Queue.js +0 -1
- package/QFactory.js +49 -17
- package/Queue.js +1 -4
- package/README.md +2 -1
- package/TODO +0 -9
- package/backends/bucket-mongo-safe.js +11 -11
- package/backends/intraorder.js +13 -11
- package/backends/mongo.js +12 -9
- package/backends/pl-mongo.js +8 -5
- package/backends/postgres.js +380 -0
- package/backends/ps-mongo.js +11 -8
- package/backends/redis-list.js +8 -8
- package/backends/redis-oq.js +8 -3
- package/backends/stream-mongo.js +10 -15
- package/package.json +12 -8
- package/stats/mem.js +0 -1
- package/.github/workflows/codeql-analysis.yml +0 -72
- package/bench/all-mongo.js +0 -108
- package/bench/multi-q.js +0 -85
- package/bench/redis-oq-consumer-producer.js +0 -52
- package/bench/redis-oq-consumer.js +0 -40
- package/bench/redis-oq-producer.js +0 -43
- package/docker-compose/docker-compose.yaml +0 -18
- package/docker-compose.yaml +0 -18
- package/examples/pipelines/builder/index.js +0 -99
- package/examples/pipelines/fromRecipe/index.js +0 -127
- package/examples/pipelines/simplest/index.js +0 -38
- package/examples/pipelines/simulation-fork/index.js +0 -115
- package/examples/snippets/01-simplest-pop-push.js +0 -49
- package/examples/snippets/02-simplest-reserve-rollback-commit.js +0 -44
- package/examples/snippets/03-simplest-producer-consumer-loops.js +0 -77
- package/examples/snippets/04-bucket-mongo-safe-insert-reserve-commit.js +0 -78
- package/examples/snippets/05-insert-reserve-rollback-deadletter.js +0 -105
- package/examples/snippets/06-random-consumer-producer.js +0 -270
- package/examples/snippets/07-stream-simple.js +0 -53
- package/examples/snippets/redislabs-consumer-producer.js +0 -44
- package/examples/snippets/with-redis-stats-and-signaller-consumer-producer.js +0 -52
- package/examples/webhooks/README.md +0 -36
- package/examples/webhooks/app.js +0 -70
- package/examples/webhooks/consumer.js +0 -98
- package/examples/webhooks/index.js +0 -55
- package/examples/webhooks/package-lock.json +0 -500
- package/examples/webhooks/package.json +0 -23
- package/examples/webhooks/wh-payload.json +0 -38
- package/playground/irc.js +0 -53
- package/playground/pl-rollback.js +0 -55
- package/playground/pl1.js +0 -74
- package/playground/q1.js +0 -34
- package/playground/simple-pl.js +0 -42
- package/playground/stream-loops.js +0 -114
- package/test/backends_bucket-at-least-once.js +0 -302
- package/test/backends_deadletter.js +0 -227
- package/test/backends_payload.js +0 -542
- package/test/backends_push-pop.js +0 -170
- package/test/backends_remove.js +0 -320
- package/test/backends_reserve-commit-rollback.js +0 -1033
- package/test/intraorder.js +0 -325
- package/test/pause.js +0 -220
- package/test/pipeline-Builder.js +0 -285
- package/test/pipeline-ChoiceLink.js +0 -241
- package/test/pipeline-DirectLink.js +0 -376
- package/test/pipeline-Sink.js +0 -175
- package/test/signal.js +0 -196
- package/test/stats.js +0 -296
- package/test/stream-mongo.js +0 -166
package/bench/all-mongo.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var async = require ('async');
|
|
3
|
-
|
|
4
|
-
var MQ = require('../backends/mongo');
|
|
5
|
-
//var signal_mongo_capped = require('../signal/mongo-capped');
|
|
6
|
-
var signal_mongo_capped = require('../signal/local');
|
|
7
|
-
var stats_mongo = require('../stats/mongo');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var factory_opts = {
|
|
11
|
-
url: 'mongodb://localhost/qeus',
|
|
12
|
-
signaller: {
|
|
13
|
-
provider: signal_mongo_capped,
|
|
14
|
-
opts: {
|
|
15
|
-
url: 'mongodb://localhost/qeus_signal',
|
|
16
|
-
channel: 'das_channel'
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
stats: {
|
|
20
|
-
provider: stats_mongo,
|
|
21
|
-
opts: {
|
|
22
|
-
url: 'mongodb://localhost/qeus_stats'
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// initialize factory
|
|
29
|
-
MQ(factory_opts, (err, factory) => {
|
|
30
|
-
if (err) {
|
|
31
|
-
return console.error(err);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
var consumed = 0;
|
|
35
|
-
var produced = 0;
|
|
36
|
-
|
|
37
|
-
function run_consumer(q) {
|
|
38
|
-
q.pop('c1', {}, (err, res) => {
|
|
39
|
-
// console.log('consumer[%s]: got res %j', q.name(), res, {});
|
|
40
|
-
consumed++;
|
|
41
|
-
|
|
42
|
-
if (consumed > 100) {
|
|
43
|
-
factory.close();
|
|
44
|
-
} else {
|
|
45
|
-
if (!(consumed % 10)) console.log('< %d', consumed);
|
|
46
|
-
|
|
47
|
-
setTimeout(function () {
|
|
48
|
-
run_consumer(q);
|
|
49
|
-
}, 222);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function run_producer(q) {
|
|
55
|
-
q.push({
|
|
56
|
-
a: 1,
|
|
57
|
-
b: '666',
|
|
58
|
-
t: new Date(),
|
|
59
|
-
n: produced
|
|
60
|
-
}, (err, res) => {
|
|
61
|
-
produced++;
|
|
62
|
-
|
|
63
|
-
if (produced > 3) {
|
|
64
|
-
|
|
65
|
-
} else {
|
|
66
|
-
if (!(produced % 10)) console.log('> %d', produced);
|
|
67
|
-
|
|
68
|
-
setTimeout(function () {
|
|
69
|
-
run_producer(q);
|
|
70
|
-
}, 33);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
var opts = {};
|
|
76
|
-
|
|
77
|
-
var q = factory.queue('bench_test_queue_0', opts);
|
|
78
|
-
// run_consumer(q);
|
|
79
|
-
// run_producer(q);
|
|
80
|
-
|
|
81
|
-
async.series ([
|
|
82
|
-
cb => q.push ({q:0, a: 'ryetyeryre 0'}, cb),
|
|
83
|
-
cb => q.push ({q:1, a: 'ryetyeryre 1'}, cb),
|
|
84
|
-
cb => q.pop ('me', (err, res) => {console.log ('>>>>>>> POP c0:', res); cb ();}),
|
|
85
|
-
cb => q.pop ('me', (err, res) => {console.log ('>>>>>>> POP c1:', res); cb ();}),
|
|
86
|
-
|
|
87
|
-
cb => {
|
|
88
|
-
q.pop ('me', (err, res) => console.log ('>>>>>>> POP c2:', res));
|
|
89
|
-
q.pop ('me', (err, res) => console.log ('>>>>>>> POP c3:', res));
|
|
90
|
-
q.pop ('me', (err, res) => console.log ('>>>>>>> POP c4:', res));
|
|
91
|
-
q.pop ('me', (err, res) => console.log ('>>>>>>> POP c5:', res));
|
|
92
|
-
q.pop ('me', (err, res) => console.log ('>>>>>>> POP c6:', res));
|
|
93
|
-
cb ();
|
|
94
|
-
},
|
|
95
|
-
cb => setTimeout (cb, 2000),
|
|
96
|
-
cb => {q.pause(true); cb ();},
|
|
97
|
-
cb => q.push ({q:2, a: 'ryetyeryre 2'}, cb),
|
|
98
|
-
cb => q.push ({q:3, a: 'ryetyeryre 3'}, cb),
|
|
99
|
-
cb => q.push ({q:4, a: 'ryetyeryre 4'}, cb),
|
|
100
|
-
cb => q.push ({q:5, a: 'ryetyeryre 5'}, cb),
|
|
101
|
-
cb => setTimeout (cb, 2000),
|
|
102
|
-
cb => {q.pause(false); cb ();},
|
|
103
|
-
cb => setTimeout (cb, 2000),
|
|
104
|
-
], () => {
|
|
105
|
-
q.cancel();
|
|
106
|
-
factory.close();
|
|
107
|
-
});
|
|
108
|
-
});
|
package/bench/multi-q.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
var async = require ('async');
|
|
2
|
-
var should = require ('should');
|
|
3
|
-
var Chance = require ('chance');
|
|
4
|
-
|
|
5
|
-
var produced = 0;
|
|
6
|
-
var consumed = 0;
|
|
7
|
-
|
|
8
|
-
var chance = new Chance();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//var MQ = require ('../backends/redis-oq');
|
|
12
|
-
//var MQ = require ('../backends/redis-list');
|
|
13
|
-
//var MQ = require ('../backends/mongo');
|
|
14
|
-
var MQ = require ('../backends/pl-mongo');
|
|
15
|
-
|
|
16
|
-
var redis_signaller = require ('../signal/redis-pubsub');
|
|
17
|
-
var redis_stats = require ('../stats/redis');
|
|
18
|
-
|
|
19
|
-
var opts = {
|
|
20
|
-
signaller: {
|
|
21
|
-
provider: new redis_signaller ()
|
|
22
|
-
},
|
|
23
|
-
stats: {
|
|
24
|
-
provider: new redis_stats ()
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
MQ (opts, function (err, factory) {
|
|
29
|
-
if (err) {
|
|
30
|
-
return console.error (err);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function run_consumer (q) {
|
|
35
|
-
q.pop ('c1', {}, function (err, res) {
|
|
36
|
-
// console.log ('consumer[%s]: got res %j', q.name(), res, {});
|
|
37
|
-
consumed++;
|
|
38
|
-
|
|
39
|
-
if (consumed > 1000000) {
|
|
40
|
-
factory.close ();
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
if (!(consumed % 10000)) console.log ('< %d', consumed)
|
|
44
|
-
// setTimeout (function () {
|
|
45
|
-
run_consumer (q);
|
|
46
|
-
// }, chance.integer({ min: 200, max: 2000 }));
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function run_producer (q) {
|
|
52
|
-
q.push ({a:1, b:'666'}, function (err, res) {
|
|
53
|
-
produced++;
|
|
54
|
-
|
|
55
|
-
if (produced > 1000000) {
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
if (!(produced % 10000)) console.log ('> %d', produced)
|
|
60
|
-
// setTimeout (function () {
|
|
61
|
-
run_producer (q);
|
|
62
|
-
// }, chance.integer({ min: 200, max: 2000 }));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var q0 = factory.queue('bench_test_queue_0', opts);
|
|
70
|
-
run_consumer (q0);
|
|
71
|
-
run_producer (q0);
|
|
72
|
-
/*
|
|
73
|
-
var q1 = factory.queue('bench_test_queue_1', opts);
|
|
74
|
-
run_consumer (q1);
|
|
75
|
-
run_producer (q1);
|
|
76
|
-
|
|
77
|
-
var q2 = factory.queue('bench_test_queue_2', opts);
|
|
78
|
-
run_consumer (q2);
|
|
79
|
-
run_producer (q2);
|
|
80
|
-
|
|
81
|
-
var q3 = factory.queue('bench_test_queue_3', opts);
|
|
82
|
-
run_consumer (q3);
|
|
83
|
-
run_producer (q3);
|
|
84
|
-
*/
|
|
85
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
var async = require ('async');
|
|
2
|
-
var should = require ('should');
|
|
3
|
-
var Chance = require ('chance');
|
|
4
|
-
|
|
5
|
-
var chance = new Chance();
|
|
6
|
-
|
|
7
|
-
function run_consumer (q) {
|
|
8
|
-
q.pop ('c1', {}, function (err, res) {
|
|
9
|
-
console.log ('consumer: got err %j', err, {});
|
|
10
|
-
console.log ('consumer: got res %j', res, {});
|
|
11
|
-
|
|
12
|
-
// setTimeout (function () {
|
|
13
|
-
run_consumer (q);
|
|
14
|
-
// }, chance.integer({ min: 200, max: 2000 }));
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function run_producer (q) {
|
|
19
|
-
q.push ({a:1, b:'666'}, function (err, res) {
|
|
20
|
-
console.log ('producer: got err %j', err, {});
|
|
21
|
-
console.log ('producer: got res %j', res, {});
|
|
22
|
-
|
|
23
|
-
setTimeout (function () {
|
|
24
|
-
run_producer (q);
|
|
25
|
-
}, (random.from0to (10) + 1) * 1000);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var MQ = require ('../backends/redis-oq');
|
|
31
|
-
var redis_signaller = require ('../signal/redis-pubsub');
|
|
32
|
-
var redis_stats = require ('../stats/redis');
|
|
33
|
-
|
|
34
|
-
var opts = {
|
|
35
|
-
signaller: {
|
|
36
|
-
provider: new redis_signaller ()
|
|
37
|
-
},
|
|
38
|
-
stats: {
|
|
39
|
-
provider: new redis_stats ()
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
MQ (opts, function (err, factory) {
|
|
44
|
-
if (err) {
|
|
45
|
-
return logger.error (err);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var q = factory.queue('bench_test_queue', opts);
|
|
49
|
-
|
|
50
|
-
run_consumer (q);
|
|
51
|
-
run_producer (q);
|
|
52
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
var async = require ('async');
|
|
2
|
-
var should = require ('should');
|
|
3
|
-
|
|
4
|
-
var counter = 0;
|
|
5
|
-
|
|
6
|
-
function run_consumer (q) {
|
|
7
|
-
q.pop ('c1', {}, function (err, res) {
|
|
8
|
-
console.log ('consumer: got err %j', err, {});
|
|
9
|
-
console.log ('consumer: got res %j', res, {});
|
|
10
|
-
|
|
11
|
-
counter++;
|
|
12
|
-
logger.info ('consumer: got %d', counter);
|
|
13
|
-
run_consumer (q);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
var MQ = require ('../backends/redis-oq');
|
|
18
|
-
|
|
19
|
-
var opts = {
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
MQ (opts, function (err, factory) {
|
|
23
|
-
if (err) {
|
|
24
|
-
return logger.error (err);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var q_opts = {
|
|
28
|
-
logger: logger,
|
|
29
|
-
signaller: {
|
|
30
|
-
provider: require ('../signal/redis-pubsub')
|
|
31
|
-
},
|
|
32
|
-
stats: {
|
|
33
|
-
provider: require ('../stats/redis')
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
var q = factory.queue ('test_queue', q_opts);
|
|
38
|
-
|
|
39
|
-
run_consumer (q);
|
|
40
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
var async = require ('async');
|
|
2
|
-
var should = require ('should');
|
|
3
|
-
|
|
4
|
-
var counter = 0;
|
|
5
|
-
|
|
6
|
-
function run_producer (q) {
|
|
7
|
-
q.push ({a:1, b:'666'}, function (err, res) {
|
|
8
|
-
console.log ('producer: got err %j', err, {});
|
|
9
|
-
console.log('producer: got res %j', res, {});
|
|
10
|
-
|
|
11
|
-
counter++;
|
|
12
|
-
console.log('producer: got %d', counter);
|
|
13
|
-
setTimeout (function () {
|
|
14
|
-
run_producer (q);
|
|
15
|
-
}, 333);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var MQ = require ('../backends/redis-oq');
|
|
21
|
-
|
|
22
|
-
var opts = {
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
MQ (opts, function (err, factory) {
|
|
26
|
-
if (err) {
|
|
27
|
-
return logger.error (err);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var q_opts = {
|
|
31
|
-
logger: logger,
|
|
32
|
-
signaller: {
|
|
33
|
-
provider: require ('../signal/redis-pubsub')
|
|
34
|
-
},
|
|
35
|
-
stats: {
|
|
36
|
-
provider: require ('../stats/redis')
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
var q = factory.queue ('test_queue', q_opts);
|
|
41
|
-
|
|
42
|
-
run_producer (q);
|
|
43
|
-
});
|
package/docker-compose.yaml
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
const Chance = require ('chance');
|
|
2
|
-
const chance = new Chance();
|
|
3
|
-
|
|
4
|
-
const MQ = require ('../../../backends/pl-mongo');
|
|
5
|
-
|
|
6
|
-
function loop (n, fn, cb) {
|
|
7
|
-
if (n == 0) return cb ();
|
|
8
|
-
fn (n, err => {
|
|
9
|
-
if (err) return cb (err);
|
|
10
|
-
setImmediate (() => loop (n-1, fn, cb));
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const factory_opts = {
|
|
15
|
-
url: 'mongodb://localhost/qeus'
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
function get_a_delay (min, max) {
|
|
19
|
-
return chance.integer ({min, max});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const num_elems = 37;
|
|
23
|
-
let processed = 0;
|
|
24
|
-
|
|
25
|
-
function sink_process (elem, done) {
|
|
26
|
-
setTimeout (() => {
|
|
27
|
-
console.log ('%s: sunk elem [a %d, choice %d, tries %d]', this.name(), elem.payload.a, elem.payload.choice, elem.payload.choice_try);
|
|
28
|
-
done();
|
|
29
|
-
|
|
30
|
-
processed++;
|
|
31
|
-
if (processed == num_elems) {
|
|
32
|
-
setTimeout (() =>{
|
|
33
|
-
console.log ('processing done, exiting');
|
|
34
|
-
process.exit (0);
|
|
35
|
-
}, 1000);
|
|
36
|
-
}
|
|
37
|
-
}, get_a_delay (10, 20));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function dl_process (elem, done) {
|
|
41
|
-
// pass element to next queue, set payload.passed to true
|
|
42
|
-
done (null, {
|
|
43
|
-
update: {
|
|
44
|
-
$set: {stamp_0: 'passed'}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function choice_process (elem, done) {
|
|
50
|
-
setTimeout (() => {
|
|
51
|
-
if (chance.bool ({likelihood: 9})) {
|
|
52
|
-
console.log ('%s: failing on elem %o on try [%d]', this.name(), elem.payload, elem.tries);
|
|
53
|
-
return done ({e: 'cl1 induced a failure'});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const idx = chance.pickone([0, 1, 2]);
|
|
57
|
-
console.log ('%s: passing elem %o to %d on try [%d]', this.name(), elem.payload, idx, elem.tries);
|
|
58
|
-
done (null, {
|
|
59
|
-
dst: idx,
|
|
60
|
-
update: {
|
|
61
|
-
$set: {stamp_1: 'passed', choice: idx, choice_try: elem.tries}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}, get_a_delay (10, 20));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// initialize factory
|
|
68
|
-
MQ (factory_opts, (err, factory) => {
|
|
69
|
-
if (err) return console.error (err);
|
|
70
|
-
|
|
71
|
-
const q_opts = {};
|
|
72
|
-
|
|
73
|
-
factory
|
|
74
|
-
.builder ()
|
|
75
|
-
.pipeline ('the-pipeline')
|
|
76
|
-
.queue ('test_pl_1', q_opts)
|
|
77
|
-
.queue ('test_pl_2', q_opts)
|
|
78
|
-
.queue ('test_pl_3', q_opts)
|
|
79
|
-
.queue ('test_pl_4', q_opts)
|
|
80
|
-
.queue ('test_pl_5', q_opts)
|
|
81
|
-
.directLink ('test_pl_1', 'test_pl_2', dl_process)
|
|
82
|
-
.choiceLink ('test_pl_2', ['test_pl_3', 'test_pl_4', 'test_pl_5'], choice_process)
|
|
83
|
-
.sink ('test_pl_3', sink_process)
|
|
84
|
-
.sink ('test_pl_4', sink_process)
|
|
85
|
-
.sink ('test_pl_5', sink_process)
|
|
86
|
-
.onError (console.log)
|
|
87
|
-
.done ((err, pl) => {
|
|
88
|
-
if (err) return console.error (err);
|
|
89
|
-
console.log ('pipeline IS READY')
|
|
90
|
-
pl.start ();
|
|
91
|
-
console.log ('pipeline IS RUNNING, inserting load')
|
|
92
|
-
|
|
93
|
-
loop (
|
|
94
|
-
num_elems,
|
|
95
|
-
(n, next) => setTimeout (() => pl.queues()['test_pl_1'].push ({a:n, b:'see it fail...'}, next), chance.integer ({min:0, max: 20})),
|
|
96
|
-
err => console.log (err || 'done')
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
const Chance = require ('chance');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const chance = new Chance();
|
|
5
|
-
|
|
6
|
-
const MQ = require ('../../../backends/pl-mongo');
|
|
7
|
-
|
|
8
|
-
function loop (n, fn, cb) {
|
|
9
|
-
if (n == 0) return cb ();
|
|
10
|
-
fn (n, err => {
|
|
11
|
-
if (err) return cb (err);
|
|
12
|
-
setImmediate (() => loop (n-1, fn, cb));
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const factory_opts = {
|
|
17
|
-
url: 'mongodb://localhost/qeus'
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const bs_src_array = [
|
|
21
|
-
`
|
|
22
|
-
const Chance = require ('chance');
|
|
23
|
-
const chance = new Chance();
|
|
24
|
-
`,
|
|
25
|
-
`
|
|
26
|
-
function get_a_delay (min, max) {
|
|
27
|
-
return chance.integer ({min, max});
|
|
28
|
-
}
|
|
29
|
-
`,
|
|
30
|
-
`
|
|
31
|
-
function sink_process (elem, done) {
|
|
32
|
-
setTimeout (() => {
|
|
33
|
-
console.log ('%s: sunk elem [a %d, choice %d, tries %d]', this.name(), elem.payload.a, elem.payload.choice, elem.payload.choice_try);
|
|
34
|
-
done();
|
|
35
|
-
|
|
36
|
-
processed++;
|
|
37
|
-
if (processed == num_elems) {
|
|
38
|
-
setTimeout (() =>{
|
|
39
|
-
console.log ('processing done, exiting');
|
|
40
|
-
process.exit (0);
|
|
41
|
-
}, 1000);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}, get_a_delay (10, 20));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function dl_process (elem, done) {
|
|
48
|
-
// pass element to next queue, set payload.passed to true
|
|
49
|
-
done (null, {
|
|
50
|
-
update: {
|
|
51
|
-
$set: {stamp_0: 'passed'}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function choice_process (elem, done) {
|
|
57
|
-
setTimeout (() => {
|
|
58
|
-
if (chance.bool ({likelihood: 9})) {
|
|
59
|
-
console.log ('%s: failing on elem %o on try [%d]', this.name(), elem.payload, elem.tries);
|
|
60
|
-
return done ({e: 'cl1 induced a failure'});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const idx = chance.pickone([0, 1, 2]);
|
|
64
|
-
console.log ('%s: passing elem %o to %d on try [%d]', this.name(), elem.payload, idx, elem.tries);
|
|
65
|
-
done (null, {
|
|
66
|
-
dst: idx,
|
|
67
|
-
update: {
|
|
68
|
-
$set: {stamp_1: 'passed', choice: idx, choice_try: elem.tries}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}, get_a_delay (10, 20));
|
|
72
|
-
}
|
|
73
|
-
`
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
const setup_src_array = [
|
|
77
|
-
`
|
|
78
|
-
const q_opts = {};
|
|
79
|
-
|
|
80
|
-
builder
|
|
81
|
-
.queue ('test_pl_1', q_opts)
|
|
82
|
-
.queue ('test_pl_2', q_opts)
|
|
83
|
-
.queue ('test_pl_3', q_opts)
|
|
84
|
-
.queue ('test_pl_4', q_opts)
|
|
85
|
-
.queue ('test_pl_5', q_opts)
|
|
86
|
-
.directLink ('test_pl_1', 'test_pl_2', dl_process)
|
|
87
|
-
.choiceLink ('test_pl_2', ['test_pl_3', 'test_pl_4', 'test_pl_5'], choice_process)
|
|
88
|
-
.sink ('test_pl_3', sink_process)
|
|
89
|
-
.sink ('test_pl_4', sink_process)
|
|
90
|
-
.sink ('test_pl_5', sink_process)
|
|
91
|
-
.onError (console.log)
|
|
92
|
-
.done (done);
|
|
93
|
-
`
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
const num_elems = 3;
|
|
97
|
-
let processed = 0;
|
|
98
|
-
|
|
99
|
-
// initialize factory
|
|
100
|
-
MQ (factory_opts, (err, factory) => {
|
|
101
|
-
if (err) return console.error (err);
|
|
102
|
-
|
|
103
|
-
factory.pipelineFromRecipe (
|
|
104
|
-
'a_test_etcher',
|
|
105
|
-
bs_src_array,
|
|
106
|
-
setup_src_array,
|
|
107
|
-
{
|
|
108
|
-
context: {
|
|
109
|
-
num_elems,
|
|
110
|
-
processed,
|
|
111
|
-
process,
|
|
112
|
-
console
|
|
113
|
-
}
|
|
114
|
-
}, (err, pl) => {
|
|
115
|
-
if (err) return console.error (err);
|
|
116
|
-
console.log ('pipeline IS READY')
|
|
117
|
-
pl.start ();
|
|
118
|
-
console.log ('pipeline IS RUNNING, inserting load')
|
|
119
|
-
|
|
120
|
-
loop (
|
|
121
|
-
num_elems,
|
|
122
|
-
(n, next) => setTimeout (() => pl.queues()['test_pl_1'].push ({a:n, b:'see it fail...'}, next), chance.integer ({min:0, max: 20})),
|
|
123
|
-
err => console.log (err || 'done')
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
var MQ = require ('../../../backends/pl-mongo');
|
|
2
|
-
var PDL = require ('../../../Pipeline/DirectLink');
|
|
3
|
-
var async = require ('async');
|
|
4
|
-
|
|
5
|
-
var factory_opts = {
|
|
6
|
-
url: 'mongodb://localhost/qeus'
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
// initialize factory
|
|
10
|
-
MQ (factory_opts, (err, factory) => {
|
|
11
|
-
if (err) return console.error (err);
|
|
12
|
-
|
|
13
|
-
// factory ready, create 2 queues on default pipeline
|
|
14
|
-
var q_opts = {};
|
|
15
|
-
var q1 = factory.queue ('test_pl_1', q_opts);
|
|
16
|
-
var q2 = factory.queue ('test_pl_2', q_opts);
|
|
17
|
-
|
|
18
|
-
// tie them up, q1 -> q2
|
|
19
|
-
var pdl = new PDL (q1, q2);
|
|
20
|
-
|
|
21
|
-
pdl.start (function (elem, done) {
|
|
22
|
-
// pass element to next queue, set payload.passed to true
|
|
23
|
-
done (null, {
|
|
24
|
-
update: {
|
|
25
|
-
$set: {passed: true}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// insert elements in the entry queue
|
|
31
|
-
async.timesLimit (3, 3, (n, next) => q1.push ({a:n, b:'see it spin...'}, next));
|
|
32
|
-
|
|
33
|
-
// read elements at the outer end
|
|
34
|
-
async.timesLimit (3, 3, (n, next) => q2.pop ('exit', (err, res) => {
|
|
35
|
-
console.log ('end point get', res);
|
|
36
|
-
next ();
|
|
37
|
-
}));
|
|
38
|
-
});
|