@nocobase/server 2.0.0-alpha.51 → 2.0.0-alpha.52
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/event-queue.d.ts +7 -1
- package/lib/event-queue.js +23 -25
- package/lib/pub-sub-manager/pub-sub-manager.js +6 -12
- package/package.json +16 -16
package/lib/event-queue.d.ts
CHANGED
|
@@ -23,6 +23,12 @@ export type QueueEventOptions = {
|
|
|
23
23
|
*/
|
|
24
24
|
interval?: number;
|
|
25
25
|
concurrency?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Shared across multiple applications.
|
|
28
|
+
* Will not use app prefix for channel name.
|
|
29
|
+
* @experimental
|
|
30
|
+
*/
|
|
31
|
+
shared?: boolean;
|
|
26
32
|
idle(): boolean;
|
|
27
33
|
process: QueueCallback;
|
|
28
34
|
};
|
|
@@ -84,7 +90,7 @@ export declare class EventQueue {
|
|
|
84
90
|
protected events: Map<string, QueueEventOptions>;
|
|
85
91
|
get channelPrefix(): string;
|
|
86
92
|
constructor(app: Application, options?: EventQueueOptions);
|
|
87
|
-
getFullChannel(channel: string): string;
|
|
93
|
+
getFullChannel(channel: string, shared?: boolean): string;
|
|
88
94
|
setAdapter<A extends IEventQueueAdapter>(adapter: A): void;
|
|
89
95
|
isConnected(): boolean;
|
|
90
96
|
connect(): Promise<void>;
|
package/lib/event-queue.js
CHANGED
|
@@ -270,16 +270,14 @@ const _EventQueue = class _EventQueue {
|
|
|
270
270
|
constructor(app, options = {}) {
|
|
271
271
|
this.app = app;
|
|
272
272
|
this.options = options;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
app.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
});
|
|
282
|
-
}
|
|
273
|
+
this.setAdapter(new MemoryEventQueueAdapter({ appName: this.app.name, logger: this.app.logger }));
|
|
274
|
+
app.on("afterStart", async () => {
|
|
275
|
+
await this.connect();
|
|
276
|
+
});
|
|
277
|
+
app.on("afterStop", async () => {
|
|
278
|
+
app.logger.info("[queue] gracefully shutting down...");
|
|
279
|
+
await this.close();
|
|
280
|
+
});
|
|
283
281
|
}
|
|
284
282
|
adapter;
|
|
285
283
|
events = /* @__PURE__ */ new Map();
|
|
@@ -287,7 +285,10 @@ const _EventQueue = class _EventQueue {
|
|
|
287
285
|
var _a;
|
|
288
286
|
return (_a = this.options) == null ? void 0 : _a.channelPrefix;
|
|
289
287
|
}
|
|
290
|
-
getFullChannel(channel) {
|
|
288
|
+
getFullChannel(channel, shared = false) {
|
|
289
|
+
if (shared) {
|
|
290
|
+
return [this.channelPrefix, channel].filter(Boolean).join(".");
|
|
291
|
+
}
|
|
291
292
|
return [this.app.name, this.channelPrefix, channel].filter(Boolean).join(".");
|
|
292
293
|
}
|
|
293
294
|
setAdapter(adapter) {
|
|
@@ -300,17 +301,13 @@ const _EventQueue = class _EventQueue {
|
|
|
300
301
|
return this.adapter.isConnected();
|
|
301
302
|
}
|
|
302
303
|
async connect() {
|
|
303
|
-
if (!this.app.serving()) {
|
|
304
|
-
this.app.logger.warn("app is not serving, will not connect to event queue");
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
304
|
if (!this.adapter) {
|
|
308
305
|
throw new Error("no adapter set, cannot connect");
|
|
309
306
|
}
|
|
310
307
|
await this.adapter.connect();
|
|
311
308
|
this.app.logger.debug(`connected to adapter, using memory? ${this.adapter instanceof MemoryEventQueueAdapter}`);
|
|
312
309
|
for (const [channel, event] of this.events.entries()) {
|
|
313
|
-
this.adapter.subscribe(this.getFullChannel(channel), event);
|
|
310
|
+
this.adapter.subscribe(this.getFullChannel(channel, event.shared), event);
|
|
314
311
|
}
|
|
315
312
|
}
|
|
316
313
|
async close() {
|
|
@@ -318,8 +315,8 @@ const _EventQueue = class _EventQueue {
|
|
|
318
315
|
return;
|
|
319
316
|
}
|
|
320
317
|
await this.adapter.close();
|
|
321
|
-
for (const channel of this.events.
|
|
322
|
-
this.adapter.unsubscribe(this.getFullChannel(channel));
|
|
318
|
+
for (const [channel, event] of this.events.entries()) {
|
|
319
|
+
this.adapter.unsubscribe(this.getFullChannel(channel, event.shared));
|
|
323
320
|
}
|
|
324
321
|
}
|
|
325
322
|
subscribe(channel, options) {
|
|
@@ -329,30 +326,31 @@ const _EventQueue = class _EventQueue {
|
|
|
329
326
|
}
|
|
330
327
|
this.events.set(channel, options);
|
|
331
328
|
if (this.isConnected()) {
|
|
332
|
-
this.adapter.subscribe(this.getFullChannel(channel
|
|
329
|
+
this.adapter.subscribe(this.getFullChannel(channel, options.shared), this.events.get(channel));
|
|
333
330
|
}
|
|
334
331
|
}
|
|
335
332
|
unsubscribe(channel) {
|
|
333
|
+
var _a;
|
|
336
334
|
if (!this.events.has(channel)) {
|
|
337
335
|
return;
|
|
338
336
|
}
|
|
339
337
|
this.events.delete(channel);
|
|
340
338
|
if (this.isConnected()) {
|
|
341
|
-
this.adapter.unsubscribe(this.getFullChannel(channel));
|
|
339
|
+
this.adapter.unsubscribe(this.getFullChannel(channel, (_a = this.events.get(channel)) == null ? void 0 : _a.shared));
|
|
342
340
|
}
|
|
343
341
|
}
|
|
344
342
|
async publish(channel, message, options = {}) {
|
|
345
|
-
if (!this.app.serving()) {
|
|
346
|
-
this.app.logger.warn("app is not serving, will not publish message to event queue");
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
343
|
if (!this.adapter) {
|
|
350
344
|
throw new Error("no adapter set, cannot publish");
|
|
351
345
|
}
|
|
352
346
|
if (!this.isConnected()) {
|
|
353
347
|
throw new Error("event queue not connected, cannot publish");
|
|
354
348
|
}
|
|
355
|
-
const
|
|
349
|
+
const event = this.events.get(channel);
|
|
350
|
+
if (!event) {
|
|
351
|
+
throw new Error(`event queue not subscribed on channel "${channel}", cannot publish`);
|
|
352
|
+
}
|
|
353
|
+
const c = this.getFullChannel(channel, event.shared);
|
|
356
354
|
this.app.logger.debug(`event queue publishing to channel(${c})`, { message });
|
|
357
355
|
await this.adapter.publish(c, message, {
|
|
358
356
|
timeout: QUEUE_DEFAULT_ACK_TIMEOUT,
|
|
@@ -35,14 +35,12 @@ var import_utils = require("@nocobase/utils");
|
|
|
35
35
|
var import_handler_manager = require("./handler-manager");
|
|
36
36
|
const createPubSubManager = /* @__PURE__ */ __name((app, options) => {
|
|
37
37
|
const pubSubManager = new PubSubManager(app, options);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
}
|
|
38
|
+
app.on("afterStart", async () => {
|
|
39
|
+
await pubSubManager.connect();
|
|
40
|
+
});
|
|
41
|
+
app.on("afterStop", async () => {
|
|
42
|
+
await pubSubManager.close();
|
|
43
|
+
});
|
|
46
44
|
return pubSubManager;
|
|
47
45
|
}, "createPubSubManager");
|
|
48
46
|
const _PubSubManager = class _PubSubManager {
|
|
@@ -72,10 +70,6 @@ const _PubSubManager = class _PubSubManager {
|
|
|
72
70
|
if (!this.adapter) {
|
|
73
71
|
return;
|
|
74
72
|
}
|
|
75
|
-
if (!this.app.serving()) {
|
|
76
|
-
this.app.logger.warn("app is not serving, will not connect to event queue");
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
73
|
await this.adapter.connect();
|
|
80
74
|
await this.handlerManager.each(async (channel, headler) => {
|
|
81
75
|
this.app.logger.debug(`[PubSubManager] subscribe ${channel} added before connected`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.52",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,20 +10,20 @@
|
|
|
10
10
|
"@koa/cors": "^5.0.0",
|
|
11
11
|
"@koa/multer": "^3.1.0",
|
|
12
12
|
"@koa/router": "^13.1.0",
|
|
13
|
-
"@nocobase/acl": "2.0.0-alpha.
|
|
14
|
-
"@nocobase/actions": "2.0.0-alpha.
|
|
15
|
-
"@nocobase/auth": "2.0.0-alpha.
|
|
16
|
-
"@nocobase/cache": "2.0.0-alpha.
|
|
17
|
-
"@nocobase/data-source-manager": "2.0.0-alpha.
|
|
18
|
-
"@nocobase/database": "2.0.0-alpha.
|
|
19
|
-
"@nocobase/evaluators": "2.0.0-alpha.
|
|
20
|
-
"@nocobase/lock-manager": "2.0.0-alpha.
|
|
21
|
-
"@nocobase/logger": "2.0.0-alpha.
|
|
22
|
-
"@nocobase/resourcer": "2.0.0-alpha.
|
|
23
|
-
"@nocobase/sdk": "2.0.0-alpha.
|
|
24
|
-
"@nocobase/snowflake-id": "2.0.0-alpha.
|
|
25
|
-
"@nocobase/telemetry": "2.0.0-alpha.
|
|
26
|
-
"@nocobase/utils": "2.0.0-alpha.
|
|
13
|
+
"@nocobase/acl": "2.0.0-alpha.52",
|
|
14
|
+
"@nocobase/actions": "2.0.0-alpha.52",
|
|
15
|
+
"@nocobase/auth": "2.0.0-alpha.52",
|
|
16
|
+
"@nocobase/cache": "2.0.0-alpha.52",
|
|
17
|
+
"@nocobase/data-source-manager": "2.0.0-alpha.52",
|
|
18
|
+
"@nocobase/database": "2.0.0-alpha.52",
|
|
19
|
+
"@nocobase/evaluators": "2.0.0-alpha.52",
|
|
20
|
+
"@nocobase/lock-manager": "2.0.0-alpha.52",
|
|
21
|
+
"@nocobase/logger": "2.0.0-alpha.52",
|
|
22
|
+
"@nocobase/resourcer": "2.0.0-alpha.52",
|
|
23
|
+
"@nocobase/sdk": "2.0.0-alpha.52",
|
|
24
|
+
"@nocobase/snowflake-id": "2.0.0-alpha.52",
|
|
25
|
+
"@nocobase/telemetry": "2.0.0-alpha.52",
|
|
26
|
+
"@nocobase/utils": "2.0.0-alpha.52",
|
|
27
27
|
"@types/decompress": "4.2.7",
|
|
28
28
|
"@types/ini": "^1.3.31",
|
|
29
29
|
"@types/koa-send": "^4.1.3",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"@types/serve-handler": "^6.1.1",
|
|
61
61
|
"@types/ws": "^8.5.5"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "b32992d8baeb4ca6616d839ca2f9c023d49476a9"
|
|
64
64
|
}
|