@webda/core 1.2.1 → 1.6.0-beta.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/lib/application.d.ts +3 -0
- package/lib/application.js +26 -22
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +185 -2
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +62 -6
- package/lib/core.js +127 -86
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +151 -6
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +42 -3
- package/lib/models/aclmodel.js +58 -3
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +46 -0
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +58 -10
- package/lib/models/coremodel.js +39 -32
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +68 -6
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/ident.d.ts +8 -2
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +16 -0
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +1 -1
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +22 -19
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +2 -0
- package/lib/models/user.js +4 -2
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +9 -2
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +63 -0
- package/lib/queues/filequeue.js +161 -0
- package/lib/queues/filequeue.js.map +1 -0
- package/lib/queues/filequeue.spec.d.ts +1 -0
- package/lib/queues/filequeue.spec.js +90 -0
- package/lib/queues/filequeue.spec.js.map +1 -0
- package/lib/queues/memoryqueue.d.ts +18 -4
- package/lib/queues/memoryqueue.js +20 -13
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -39
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +27 -0
- package/lib/queues/pubsubservice.js +21 -0
- package/lib/queues/pubsubservice.js.map +1 -0
- package/lib/queues/queue.spec.js +16 -7
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +108 -13
- package/lib/queues/queueservice.js +100 -36
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.js +4 -6
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +27 -2
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +110 -5
- package/lib/services/asyncevents.js +134 -39
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +58 -4
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +57 -5
- package/lib/services/authentication.js +93 -84
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +118 -82
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +175 -48
- package/lib/services/binary.js +205 -170
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +22 -3
- package/lib/services/binary.spec.js +327 -22
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +94 -13
- package/lib/services/configuration.js +98 -28
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +40 -1
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +4 -4
- package/lib/services/cron.js +37 -53
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.d.ts +1 -0
- package/lib/services/cron.spec.js +76 -0
- package/lib/services/cron.spec.js.map +1 -0
- package/lib/services/debugmailer.spec.js +18 -4
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.js +22 -13
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.d.ts +1 -0
- package/lib/services/echo.spec.js +52 -0
- package/lib/services/echo.spec.js.map +1 -0
- package/lib/services/filebinary.d.ts +16 -9
- package/lib/services/filebinary.js +58 -73
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +8 -1
- package/lib/services/filebinary.spec.js +133 -7
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +9 -3
- package/lib/services/fileconfiguration.js +13 -6
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +100 -5
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +8 -2
- package/lib/services/kubernetesconfiguration.js +16 -5
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +53 -16
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +11 -2
- package/lib/services/mailer.js +28 -34
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +69 -23
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +5 -2
- package/lib/services/oauth.js +22 -8
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +33 -3
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/resource.spec.js +39 -2
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +16 -0
- package/lib/services/service.js +47 -6
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.d.ts +1 -0
- package/lib/services/service.spec.js +119 -0
- package/lib/services/service.spec.js.map +1 -0
- package/lib/stores/aggregator.d.ts +43 -0
- package/lib/stores/aggregator.js +106 -0
- package/lib/stores/aggregator.js.map +1 -0
- package/lib/stores/file.d.ts +49 -11
- package/lib/stores/file.js +84 -81
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +6 -1
- package/lib/stores/file.spec.js +134 -9
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +151 -0
- package/lib/stores/mapper.js +294 -0
- package/lib/stores/mapper.js.map +1 -0
- package/lib/stores/mapper.spec.d.ts +1 -0
- package/lib/stores/mapper.spec.js +55 -0
- package/lib/stores/mapper.spec.js.map +1 -0
- package/lib/stores/memory.d.ts +52 -7
- package/lib/stores/memory.js +71 -33
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +6 -1
- package/lib/stores/memory.spec.js +65 -4
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +263 -126
- package/lib/stores/store.js +285 -493
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +20 -0
- package/lib/stores/store.spec.js +242 -18
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/test.d.ts +1 -7
- package/lib/test.js +3 -12
- package/lib/test.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.d.ts +1 -0
- package/lib/utils/abstractdeployer.spec.js +23 -0
- package/lib/utils/abstractdeployer.spec.js.map +1 -0
- package/lib/utils/context.d.ts +25 -2
- package/lib/utils/context.js +33 -12
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +81 -11
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +12 -0
- package/lib/utils/cookie.js +13 -1
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +42 -11
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +23 -4
- package/lib/utils/logger.js +29 -6
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +8 -0
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.d.ts +5 -5
- package/lib/utils/serializers.js +10 -10
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +41 -16
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/waiter.d.ts +59 -1
- package/lib/utils/waiter.js +86 -3
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +48 -4
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +16 -11
- package/test/badapp/package.json +4 -0
- package/test/badapp/webda.config.json +1 -0
- package/test/cachedapp/webda.config.json +7 -0
- package/test/config-file-no-reload.json +70 -0
- package/test/config-file-reload.json +7 -1
- package/test/config-kube-reload.json +7 -1
- package/test/config.json +45 -21
- package/test/config.old-default.json +0 -16
- package/test/config.old.json +0 -16
- package/test/deployments/invalid.json +1 -0
- package/test/moddas/fakeservice.js +5 -0
- package/test/models/ident.js +10 -14
- package/test/models/task.js +2 -4
|
@@ -14,68 +14,145 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
+
var MemoryQueueTest_1;
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
const assert = require("assert");
|
|
19
20
|
const mocha_1 = require("@testdeck/mocha");
|
|
20
21
|
const memoryqueue_1 = require("./memoryqueue");
|
|
21
22
|
const queue_spec_1 = require("./queue.spec");
|
|
22
|
-
|
|
23
|
+
class Title {
|
|
24
|
+
constructor(title) {
|
|
25
|
+
this.title = title;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
let MemoryQueueTest = MemoryQueueTest_1 = class MemoryQueueTest extends queue_spec_1.QueueTest {
|
|
29
|
+
receiveMessage(proto) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
console.log("receiveMessage", MemoryQueueTest_1.seq);
|
|
32
|
+
MemoryQueueTest_1.seq++;
|
|
33
|
+
switch (MemoryQueueTest_1.seq) {
|
|
34
|
+
case 1:
|
|
35
|
+
// Test the resume if no messages available
|
|
36
|
+
return [];
|
|
37
|
+
case 2:
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
ReceiptHandle: "msg1",
|
|
41
|
+
Message: MemoryQueueTest_1.queue.unserialize(JSON.stringify({ title: "plop" }), proto)
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
case 3:
|
|
45
|
+
throw Error();
|
|
46
|
+
case 4:
|
|
47
|
+
// An error occured it should double the pause
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
MemoryQueueTest_1.failedIterations.push(MemoryQueueTest_1.queue.failedIterations);
|
|
50
|
+
return Promise.resolve([
|
|
51
|
+
{
|
|
52
|
+
ReceiptHandle: "msg2",
|
|
53
|
+
Message: MemoryQueueTest_1.queue.unserialize(JSON.stringify({ title: "plop2" }), proto)
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
case 5:
|
|
57
|
+
// Error on callback dont generate a double delay
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
MemoryQueueTest_1.failedIterations.push(MemoryQueueTest_1.queue.failedIterations);
|
|
60
|
+
MemoryQueueTest_1.resolve(MemoryQueueTest_1.workerPromise.cancel());
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
receiveMessageParallelism(proto) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
MemoryQueueTest_1.seq++;
|
|
68
|
+
switch (MemoryQueueTest_1.seq) {
|
|
69
|
+
case 1:
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
ReceiptHandle: "msg1",
|
|
73
|
+
Message: { title: "plop" }
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
ReceiptHandle: "msg2",
|
|
77
|
+
Message: { title: "plop2" }
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
case 2:
|
|
81
|
+
MemoryQueueTest_1.resolve(MemoryQueueTest_1.workerPromise.cancel());
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
23
86
|
worker() {
|
|
24
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
MemoryQueueTest_1.failedIterations = [];
|
|
25
89
|
yield new Promise(resolve => {
|
|
26
|
-
|
|
27
|
-
let
|
|
90
|
+
MemoryQueueTest_1.resolve = resolve;
|
|
91
|
+
let queue = new memoryqueue_1.MemoryQueue(this.webda, "q", {
|
|
92
|
+
workerParallelism: false
|
|
93
|
+
});
|
|
94
|
+
MemoryQueueTest_1.queue = queue;
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
queue.delayer = () => 1;
|
|
97
|
+
MemoryQueueTest_1.seq = 0;
|
|
28
98
|
// @ts-ignore
|
|
29
99
|
queue._webda = {
|
|
30
100
|
log: () => { }
|
|
31
101
|
};
|
|
32
|
-
queue.receiveMessage = ()
|
|
33
|
-
seq++;
|
|
34
|
-
switch (seq) {
|
|
35
|
-
case 1:
|
|
36
|
-
// Test the resume if no messages available
|
|
37
|
-
return Promise.resolve([]);
|
|
38
|
-
case 2:
|
|
39
|
-
return Promise.resolve([
|
|
40
|
-
{
|
|
41
|
-
ReceiptHandle: "msg1",
|
|
42
|
-
Body: '{"title":"plop"}'
|
|
43
|
-
}
|
|
44
|
-
]);
|
|
45
|
-
case 3:
|
|
46
|
-
throw Error();
|
|
47
|
-
case 4:
|
|
48
|
-
// An error occured it should double the pause
|
|
49
|
-
assert.strictEqual(queue.pause, 2);
|
|
50
|
-
return Promise.resolve([
|
|
51
|
-
{
|
|
52
|
-
ReceiptHandle: "msg2",
|
|
53
|
-
Body: '{"title":"plop2"}'
|
|
54
|
-
}
|
|
55
|
-
]);
|
|
56
|
-
case 5:
|
|
57
|
-
// Error on callback dont generate a double delay
|
|
58
|
-
assert.strictEqual(queue.pause, 2);
|
|
59
|
-
resolve(queue.stop());
|
|
60
|
-
}
|
|
61
|
-
};
|
|
102
|
+
queue.receiveMessage = this.receiveMessage.bind(queue);
|
|
62
103
|
queue.deleteMessage = (handle) => __awaiter(this, void 0, void 0, function* () {
|
|
63
104
|
// Should only have the msg1 handle in deleteMessage as msg2 is fake error
|
|
64
105
|
assert.strictEqual(handle, "msg1");
|
|
65
106
|
});
|
|
66
|
-
let callback = event => {
|
|
67
|
-
switch (seq) {
|
|
107
|
+
let callback = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
switch (MemoryQueueTest_1.seq) {
|
|
68
109
|
case 2:
|
|
69
110
|
assert.strictEqual(event.title, "plop");
|
|
70
111
|
return;
|
|
71
112
|
case 4:
|
|
72
113
|
// Simulate error in callback
|
|
73
114
|
throw Error();
|
|
74
|
-
return;
|
|
75
115
|
}
|
|
76
|
-
};
|
|
77
|
-
queue.
|
|
116
|
+
});
|
|
117
|
+
MemoryQueueTest_1.workerPromise = queue.consume(callback, Title);
|
|
118
|
+
});
|
|
119
|
+
assert.deepStrictEqual(MemoryQueueTest_1.failedIterations, [1, 0]);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
parallelized() {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
let op = 0;
|
|
125
|
+
const run = (parallel) => __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
yield new Promise(resolve => {
|
|
127
|
+
let queue = new memoryqueue_1.MemoryQueue(this.webda, "q", { workerParallelism: parallel });
|
|
128
|
+
MemoryQueueTest_1.queue = queue;
|
|
129
|
+
MemoryQueueTest_1.resolve = resolve;
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
queue.delayer = () => 1;
|
|
132
|
+
MemoryQueueTest_1.seq = 0;
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
queue._webda = {
|
|
135
|
+
log: () => { }
|
|
136
|
+
};
|
|
137
|
+
queue.receiveMessage = this.receiveMessageParallelism.bind(queue);
|
|
138
|
+
queue.deleteMessage = (handle) => __awaiter(this, void 0, void 0, function* () { });
|
|
139
|
+
let callback = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
if (event.title === "plop") {
|
|
141
|
+
yield this.sleep(300);
|
|
142
|
+
op = 1;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
yield this.sleep(100);
|
|
146
|
+
op *= 2;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
MemoryQueueTest_1.workerPromise = queue.consume(callback, undefined);
|
|
150
|
+
});
|
|
78
151
|
});
|
|
152
|
+
yield run(true);
|
|
153
|
+
assert.strictEqual(op, 1, 'It should have been run in parallel so op=0 as *2 will happen before =1"');
|
|
154
|
+
yield run(false);
|
|
155
|
+
assert.strictEqual(op, 2, 'It should have been run in parallel so op=2 as *2 will happen after =1"');
|
|
79
156
|
});
|
|
80
157
|
}
|
|
81
158
|
basic() {
|
|
@@ -88,18 +165,44 @@ let MemoryQueueTest = class MemoryQueueTest extends queue_spec_1.QueueTest {
|
|
|
88
165
|
assert.strictEqual(queue.getParameters().expire, 30000, "default should be 30s");
|
|
89
166
|
queue.getParameters().expire = 1000;
|
|
90
167
|
queue.__clean();
|
|
168
|
+
// Should not have issue with unknown receipt
|
|
169
|
+
queue.deleteMessage("bouzouf");
|
|
91
170
|
assert.strictEqual((yield queue.receiveMessage()).length, 0);
|
|
92
171
|
return this.simple(queue);
|
|
93
172
|
});
|
|
94
173
|
}
|
|
174
|
+
uuid() {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
let queue = this.getService("memoryqueue");
|
|
177
|
+
let first = true;
|
|
178
|
+
let callCount = 0;
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
queue._queue = new Proxy(queue._queue, {
|
|
181
|
+
get: (q, prop) => {
|
|
182
|
+
callCount += 1;
|
|
183
|
+
if (callCount === 1) {
|
|
184
|
+
return "plop";
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
yield queue.sendMessage({});
|
|
189
|
+
assert.strictEqual(callCount, 2);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
95
192
|
};
|
|
96
193
|
__decorate([
|
|
97
194
|
mocha_1.test
|
|
98
195
|
], MemoryQueueTest.prototype, "worker", null);
|
|
196
|
+
__decorate([
|
|
197
|
+
mocha_1.test
|
|
198
|
+
], MemoryQueueTest.prototype, "parallelized", null);
|
|
99
199
|
__decorate([
|
|
100
200
|
mocha_1.test
|
|
101
201
|
], MemoryQueueTest.prototype, "basic", null);
|
|
102
|
-
|
|
202
|
+
__decorate([
|
|
203
|
+
mocha_1.test
|
|
204
|
+
], MemoryQueueTest.prototype, "uuid", null);
|
|
205
|
+
MemoryQueueTest = MemoryQueueTest_1 = __decorate([
|
|
103
206
|
mocha_1.suite
|
|
104
207
|
], MemoryQueueTest);
|
|
105
208
|
//# sourceMappingURL=memoryqueue.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoryqueue.spec.js","sourceRoot":"","sources":["../../src/queues/memoryqueue.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memoryqueue.spec.js","sourceRoot":"","sources":["../../src/queues/memoryqueue.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iCAAiC;AACjC,2CAA8C;AAE9C,+CAA4C;AAC5C,6CAAyC;AAEzC,MAAM,KAAK;IAGT,YAAY,KAAc;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,IAAM,eAAe,uBAArB,MAAM,eAAgB,SAAQ,sBAAS;IAO/B,cAAc,CAAI,KAAqB;;YAC3C,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,iBAAe,CAAC,GAAG,CAAC,CAAC;YACnD,iBAAe,CAAC,GAAG,EAAE,CAAC;YACtB,QAAQ,iBAAe,CAAC,GAAG,EAAE;gBAC3B,KAAK,CAAC;oBACJ,2CAA2C;oBAC3C,OAAO,EAAE,CAAC;gBACZ,KAAK,CAAC;oBACJ,OAAO;wBACL;4BACE,aAAa,EAAE,MAAM;4BACrB,OAAO,EAAE,iBAAe,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAA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G,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE;gBACrC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;oBACf,SAAS,IAAI,CAAC,CAAC;oBACf,IAAI,SAAS,KAAK,CAAC,EAAE;wBACnB,OAAO,MAAM,CAAC;qBACf;gBACH,CAAC;aACF,CAAC,CAAC;YACH,MAAM,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YAC5B,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QACnC,CAAC;KAAA;CACF,CAAA;AAvGC;IADC,YAAI;6CAkCJ;AAGD;IADC,YAAI;mDAiCJ;AAGD;IADC,YAAI;4CAcJ;AAGD;IADC,YAAI;2CAgBJ;AArKG,eAAe;IADpB,aAAK;GACA,eAAe,CAsKpB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Service, ServiceParameters } from "../services/service";
|
|
2
|
+
import { CancelablePromise } from "../utils/waiter";
|
|
3
|
+
export default abstract class PubSubService<T = any, K extends ServiceParameters = ServiceParameters> extends Service<K> {
|
|
4
|
+
/**
|
|
5
|
+
* Send an event to the queue
|
|
6
|
+
* @param event
|
|
7
|
+
*/
|
|
8
|
+
abstract sendMessage(event: T): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Unserialize into class
|
|
11
|
+
* @param data
|
|
12
|
+
* @param proto
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
unserialize<L>(data: string, proto?: {
|
|
16
|
+
new (): L;
|
|
17
|
+
}): L;
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to a channel calling the callback with every Event received
|
|
20
|
+
* @param callback
|
|
21
|
+
* @param eventPrototype
|
|
22
|
+
*/
|
|
23
|
+
abstract consume(callback: (event: T) => Promise<void>, eventPrototype?: {
|
|
24
|
+
new (): T;
|
|
25
|
+
}, onBind?: () => void): CancelablePromise;
|
|
26
|
+
}
|
|
27
|
+
export { PubSubService };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PubSubService = void 0;
|
|
4
|
+
const service_1 = require("../services/service");
|
|
5
|
+
class PubSubService extends service_1.Service {
|
|
6
|
+
/**
|
|
7
|
+
* Unserialize into class
|
|
8
|
+
* @param data
|
|
9
|
+
* @param proto
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
unserialize(data, proto) {
|
|
13
|
+
if (proto) {
|
|
14
|
+
return Object.assign(new proto(), JSON.parse(data));
|
|
15
|
+
}
|
|
16
|
+
return JSON.parse(data);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = PubSubService;
|
|
20
|
+
exports.PubSubService = PubSubService;
|
|
21
|
+
//# sourceMappingURL=pubsubservice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pubsubservice.js","sourceRoot":"","sources":["../../src/queues/pubsubservice.ts"],"names":[],"mappings":";;;AAAA,iDAAiE;AAGjE,MAA8B,aAG5B,SAAQ,iBAAU;IAOlB;;;;;OAKG;IACH,WAAW,CAAI,IAAY,EAAE,KAAqB;QAChD,IAAI,KAAK,EAAE;YACT,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;SACrD;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAYF;AAjCD,gCAiCC;AAEQ,sCAAa"}
|
package/lib/queues/queue.spec.js
CHANGED
|
@@ -12,20 +12,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.QueueTest = void 0;
|
|
13
13
|
const test_1 = require("../test");
|
|
14
14
|
const assert = require("assert");
|
|
15
|
+
class QueueItemTest {
|
|
16
|
+
constructor(type) {
|
|
17
|
+
this.type = type;
|
|
18
|
+
}
|
|
19
|
+
getDouble() {
|
|
20
|
+
return this.type * 2;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
15
23
|
class QueueTest extends test_1.WebdaTest {
|
|
16
24
|
simple(queue, inconsistentSize = false) {
|
|
17
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
26
|
var msg;
|
|
19
|
-
yield queue.sendMessage(
|
|
20
|
-
type: 1
|
|
21
|
-
});
|
|
27
|
+
yield queue.sendMessage(new QueueItemTest(1));
|
|
22
28
|
let size = yield queue.size();
|
|
23
29
|
if (!inconsistentSize) {
|
|
24
30
|
assert.strictEqual(size, 1);
|
|
25
31
|
}
|
|
26
|
-
yield queue.sendMessage(
|
|
27
|
-
type: 2
|
|
28
|
-
});
|
|
32
|
+
yield queue.sendMessage(new QueueItemTest(2));
|
|
29
33
|
// Pause for 1s - to verify the repopulation
|
|
30
34
|
yield this.sleep(1000);
|
|
31
35
|
size = yield queue.size();
|
|
@@ -33,6 +37,7 @@ class QueueTest extends test_1.WebdaTest {
|
|
|
33
37
|
assert.strictEqual(size, 2);
|
|
34
38
|
}
|
|
35
39
|
msg = yield queue.receiveMessage();
|
|
40
|
+
assert.strictEqual(msg[0].Message.getDouble, undefined);
|
|
36
41
|
size = yield queue.size();
|
|
37
42
|
if (!inconsistentSize) {
|
|
38
43
|
assert.strictEqual(size, 2);
|
|
@@ -42,13 +47,17 @@ class QueueTest extends test_1.WebdaTest {
|
|
|
42
47
|
}
|
|
43
48
|
// Pause for 1s - to verify the repopulation
|
|
44
49
|
yield this.sleep(1000);
|
|
45
|
-
msg = yield queue.receiveMessage();
|
|
50
|
+
msg = yield queue.receiveMessage(QueueItemTest);
|
|
51
|
+
assert.notStrictEqual(msg[0].Message.getDouble, undefined);
|
|
46
52
|
if (!inconsistentSize) {
|
|
47
53
|
assert.strictEqual(msg.length, 1);
|
|
48
54
|
}
|
|
49
55
|
if (msg.length > 0) {
|
|
50
56
|
yield queue.deleteMessage(msg[0].ReceiptHandle);
|
|
51
57
|
}
|
|
58
|
+
if (!inconsistentSize) {
|
|
59
|
+
assert.strictEqual(yield queue.size(), 0);
|
|
60
|
+
}
|
|
52
61
|
});
|
|
53
62
|
}
|
|
54
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.spec.js","sourceRoot":"","sources":["../../src/queues/queue.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kCAAoC;AACpC,iCAAiC;AAEjC,MAAM,SAAU,SAAQ,gBAAS;IACzB,MAAM,CAAC,KAAK,EAAE,mBAA4B,KAAK;;YACnD,IAAI,GAAG,CAAC;YACR,MAAM,KAAK,CAAC,WAAW,CAAC
|
|
1
|
+
{"version":3,"file":"queue.spec.js","sourceRoot":"","sources":["../../src/queues/queue.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kCAAoC;AACpC,iCAAiC;AAEjC,MAAM,aAAa;IAGjB,YAAY,IAAa;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IACvB,CAAC;CACF;AAED,MAAM,SAAU,SAAQ,gBAAS;IACzB,MAAM,CAAC,KAAK,EAAE,mBAA4B,KAAK;;YACnD,IAAI,GAAG,CAAC;YACR,MAAM,KAAK,CAAC,WAAW,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9C,IAAI,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,gBAAgB,EAAE;gBACrB,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;aAC7B;YACD,MAAM,KAAK,CAAC,WAAW,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9C,4CAA4C;YAC5C,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvB,IAAI,GAAG,MAAM,KAAK,CAA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-1,24 +1,119 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ServiceParameters } from "../services/service";
|
|
3
|
+
import { WaitDelayerDefinition, WaitDelayer, CancelablePromise } from "../utils/waiter";
|
|
4
|
+
import { PubSubService } from "./pubsubservice";
|
|
5
|
+
/**
|
|
6
|
+
* Raw message from queue
|
|
7
|
+
*/
|
|
8
|
+
export interface MessageReceipt<T = any> {
|
|
9
|
+
/**
|
|
10
|
+
* Message
|
|
11
|
+
*/
|
|
12
|
+
Message: T;
|
|
13
|
+
/**
|
|
14
|
+
* Id of message to acknowledge
|
|
15
|
+
*/
|
|
16
|
+
ReceiptHandle: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @inheritdoc
|
|
20
|
+
*/
|
|
21
|
+
export declare class QueueParameters extends ServiceParameters {
|
|
22
|
+
/**
|
|
23
|
+
* Delayer between two failed attempts to process messages
|
|
24
|
+
*/
|
|
25
|
+
workerDelayer?: WaitDelayerDefinition;
|
|
26
|
+
/**
|
|
27
|
+
* Define if worker should process multi message received in //
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
workerParallelism?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Max number of queue consumers
|
|
33
|
+
* Queue will auto increase to this max number if queue is loaded
|
|
34
|
+
* and it will decrease to just one consumer if no messages are available
|
|
35
|
+
*
|
|
36
|
+
* @default 10
|
|
37
|
+
*/
|
|
38
|
+
maxConsumers: number;
|
|
39
|
+
/**
|
|
40
|
+
* @inheritdoc
|
|
41
|
+
*/
|
|
42
|
+
constructor(params: any);
|
|
43
|
+
}
|
|
2
44
|
/**
|
|
3
45
|
* AbstractQueue implements the worker system
|
|
4
46
|
*
|
|
5
|
-
* A
|
|
47
|
+
* A Consumer allows you to define how to process message from
|
|
6
48
|
* the queue, implementing the retries policy
|
|
7
49
|
*
|
|
8
50
|
* @category CoreServices
|
|
9
51
|
*/
|
|
10
|
-
declare abstract class Queue<T extends
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
52
|
+
declare abstract class Queue<T = any, K extends QueueParameters = QueueParameters> extends PubSubService<T, K> {
|
|
53
|
+
/**
|
|
54
|
+
* Current timeout handler
|
|
55
|
+
*/
|
|
56
|
+
protected _timeout: NodeJS.Timeout;
|
|
57
|
+
/**
|
|
58
|
+
* Callback function to call for each message
|
|
59
|
+
*/
|
|
60
|
+
private callback;
|
|
61
|
+
/**
|
|
62
|
+
* Current pause instance
|
|
63
|
+
*/
|
|
64
|
+
protected failedIterations: number;
|
|
65
|
+
/**
|
|
66
|
+
* Delayer
|
|
67
|
+
*/
|
|
68
|
+
protected delayer: WaitDelayer;
|
|
69
|
+
eventPrototype: new () => T;
|
|
70
|
+
/**
|
|
71
|
+
* Receive one or several messages
|
|
72
|
+
*/
|
|
73
|
+
abstract receiveMessage<L>(proto?: {
|
|
74
|
+
new (): L;
|
|
75
|
+
}): Promise<MessageReceipt<L>[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Delete one message based on its receipt
|
|
78
|
+
* @param id
|
|
79
|
+
*/
|
|
17
80
|
abstract deleteMessage(id: string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Return the size of the current queue
|
|
83
|
+
*/
|
|
18
84
|
abstract size(): Promise<number>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Create the delayer
|
|
87
|
+
*/
|
|
88
|
+
resolve(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Receive and process message from the queue
|
|
91
|
+
*
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
protected consumerReceiveMessage(): Promise<{
|
|
95
|
+
speed: number;
|
|
96
|
+
items: number;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Return the max consumers for the queue
|
|
100
|
+
*
|
|
101
|
+
* It is overridable so if a queue can retrieve several message at once
|
|
102
|
+
* it can just use the worker // and several messages at once
|
|
103
|
+
*
|
|
104
|
+
* SQS for example will return this.parameters.maxConsumers / 10
|
|
105
|
+
*
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
getMaxConsumers(): number;
|
|
109
|
+
/**
|
|
110
|
+
* Work a queue calling the callback with every Event received
|
|
111
|
+
* If the callback is called without exception the `deleteMessage` is called
|
|
112
|
+
* @param callback
|
|
113
|
+
* @param eventPrototype
|
|
114
|
+
*/
|
|
115
|
+
consume(callback: (event: T) => Promise<void>, eventPrototype?: {
|
|
116
|
+
new (): T;
|
|
117
|
+
}): CancelablePromise;
|
|
23
118
|
}
|
|
24
119
|
export { Queue };
|