@nocobase/server 1.8.6 → 1.8.8
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 +4 -4
- package/lib/event-queue.js +41 -33
- package/package.json +15 -15
package/lib/event-queue.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type QueueCallbackOptions = {
|
|
|
15
15
|
retried?: number;
|
|
16
16
|
signal?: AbortSignal;
|
|
17
17
|
};
|
|
18
|
-
export type QueueCallback = (message: any, options: QueueCallbackOptions) => Promise<void
|
|
18
|
+
export type QueueCallback = (message: any, options: QueueCallbackOptions) => Promise<void>;
|
|
19
19
|
export type QueueEventOptions = {
|
|
20
20
|
/**
|
|
21
21
|
* @experimental
|
|
@@ -53,9 +53,9 @@ export declare class MemoryEventQueueAdapter implements IEventQueueAdapter {
|
|
|
53
53
|
content: any;
|
|
54
54
|
options?: QueueMessageOptions;
|
|
55
55
|
}[]>;
|
|
56
|
-
get processing(): Promise<void[]>;
|
|
56
|
+
get processing(): Promise<Promise<void>[][]>;
|
|
57
57
|
private get storagePath();
|
|
58
|
-
listen: (channel: string) =>
|
|
58
|
+
listen: (channel: string) => void;
|
|
59
59
|
constructor(options: {
|
|
60
60
|
appName: string;
|
|
61
61
|
});
|
|
@@ -69,7 +69,7 @@ export declare class MemoryEventQueueAdapter implements IEventQueueAdapter {
|
|
|
69
69
|
unsubscribe(channel: string): void;
|
|
70
70
|
publish(channel: string, content: any, options?: QueueMessageOptions): void;
|
|
71
71
|
consume(channel: string, once?: boolean): Promise<void>;
|
|
72
|
-
read(channel: string): Promise<void
|
|
72
|
+
read(channel: string, n: number): Promise<void>[];
|
|
73
73
|
process(channel: string, { id, message }: {
|
|
74
74
|
id: any;
|
|
75
75
|
message: any;
|
package/lib/event-queue.js
CHANGED
|
@@ -73,26 +73,37 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
73
73
|
get storagePath() {
|
|
74
74
|
return import_path.default.resolve(process.cwd(), "storage", "apps", this.options.appName, "event-queue.json");
|
|
75
75
|
}
|
|
76
|
-
listen = /* @__PURE__ */ __name(
|
|
76
|
+
listen = /* @__PURE__ */ __name((channel) => {
|
|
77
77
|
if (!this.connected) {
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
if (this.reading.has(channel)) {
|
|
81
|
-
console.debug(`memory queue (${channel}) is already reading, waiting last reading to end...`);
|
|
82
|
-
await this.reading.get(channel);
|
|
83
|
-
}
|
|
84
80
|
const event = this.events.get(channel);
|
|
85
81
|
if (!event) {
|
|
86
82
|
console.warn(`memory queue (${channel}) not found, skipping...`);
|
|
87
83
|
return;
|
|
88
84
|
}
|
|
89
85
|
if (!event.idle()) {
|
|
90
|
-
console.debug(`memory queue (${channel}) is not idle, skipping...`);
|
|
91
86
|
return;
|
|
92
87
|
}
|
|
93
|
-
const reading = this.
|
|
88
|
+
const reading = this.reading.get(channel) || [];
|
|
89
|
+
const count = (event.concurrency || QUEUE_DEFAULT_CONCURRENCY) - reading.length;
|
|
90
|
+
if (count <= 0) {
|
|
91
|
+
console.debug(
|
|
92
|
+
`memory queue (${channel}) is already reading as max concurrency (${reading.length}), waiting last reading to end...`
|
|
93
|
+
);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
console.debug(`reading more from queue (${channel}), count: ${count}`);
|
|
97
|
+
this.read(channel, count).forEach((promise) => {
|
|
98
|
+
reading.push(promise);
|
|
99
|
+
promise.finally(() => {
|
|
100
|
+
const index = reading.indexOf(promise);
|
|
101
|
+
if (index > -1) {
|
|
102
|
+
reading.splice(index, 1);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
94
106
|
this.reading.set(channel, reading);
|
|
95
|
-
await reading;
|
|
96
107
|
}, "listen");
|
|
97
108
|
isConnected() {
|
|
98
109
|
return this.connected;
|
|
@@ -149,6 +160,9 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
149
160
|
});
|
|
150
161
|
}
|
|
151
162
|
async close() {
|
|
163
|
+
if (!this.connected) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
152
166
|
this.connected = false;
|
|
153
167
|
if (this.processing) {
|
|
154
168
|
console.info("memory queue waiting for processing job...");
|
|
@@ -200,7 +214,7 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
200
214
|
const interval = event.interval || QUEUE_DEFAULT_INTERVAL;
|
|
201
215
|
const queue = this.queues.get(channel);
|
|
202
216
|
if (event.idle() && (queue == null ? void 0 : queue.length)) {
|
|
203
|
-
|
|
217
|
+
this.listen(channel);
|
|
204
218
|
}
|
|
205
219
|
if (once) {
|
|
206
220
|
break;
|
|
@@ -208,47 +222,41 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
208
222
|
await (0, import_utils.sleep)(interval);
|
|
209
223
|
}
|
|
210
224
|
}
|
|
211
|
-
|
|
212
|
-
const event = this.events.get(channel);
|
|
213
|
-
if (!event) {
|
|
214
|
-
this.reading.delete(channel);
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
225
|
+
read(channel, n) {
|
|
217
226
|
const queue = this.queues.get(channel);
|
|
218
|
-
if (queue == null ? void 0 : queue.length) {
|
|
219
|
-
|
|
220
|
-
console.debug(`memory queue (${channel}) read ${messages.length} messages`, messages);
|
|
221
|
-
queue.splice(0, messages.length);
|
|
222
|
-
const batch = messages.map(({ id, ...message }) => this.process(channel, { id, message }));
|
|
223
|
-
await Promise.all(batch);
|
|
227
|
+
if (!(queue == null ? void 0 : queue.length)) {
|
|
228
|
+
return [];
|
|
224
229
|
}
|
|
225
|
-
|
|
230
|
+
const messages = queue.slice(0, n);
|
|
231
|
+
console.debug(`memory queue (${channel}) read ${messages.length} messages`, messages);
|
|
232
|
+
queue.splice(0, messages.length);
|
|
233
|
+
const batch = messages.map(({ id, ...message }) => this.process(channel, { id, message }));
|
|
234
|
+
return batch;
|
|
226
235
|
}
|
|
227
236
|
async process(channel, { id, message }) {
|
|
228
237
|
const event = this.events.get(channel);
|
|
229
238
|
const { content, options: { timeout = QUEUE_DEFAULT_ACK_TIMEOUT, maxRetries = 0, retried = 0 } = {} } = message;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
239
|
+
console.debug(`memory queue (${channel}) processing message (${id})...`, content);
|
|
240
|
+
return (async () => event.process(content, {
|
|
241
|
+
id,
|
|
242
|
+
retried,
|
|
243
|
+
signal: AbortSignal.timeout(timeout)
|
|
244
|
+
}))().then(() => {
|
|
237
245
|
console.debug(`memory queue (${channel}) consumed message (${id})`);
|
|
238
|
-
}
|
|
246
|
+
}).catch((ex) => {
|
|
239
247
|
if (maxRetries > 0 && retried < maxRetries) {
|
|
240
248
|
const currentRetry = retried + 1;
|
|
241
249
|
console.warn(
|
|
242
250
|
`memory queue (${channel}) consum message (${id}) failed, retrying (${currentRetry} / ${maxRetries})...`,
|
|
243
251
|
ex
|
|
244
252
|
);
|
|
245
|
-
|
|
253
|
+
setTimeout(() => {
|
|
246
254
|
this.publish(channel, content, { timeout, maxRetries, retried: currentRetry, timestamp: Date.now() });
|
|
247
|
-
});
|
|
255
|
+
}, 500);
|
|
248
256
|
} else {
|
|
249
257
|
console.error(ex);
|
|
250
258
|
}
|
|
251
|
-
}
|
|
259
|
+
});
|
|
252
260
|
}
|
|
253
261
|
};
|
|
254
262
|
__name(_MemoryEventQueueAdapter, "MemoryEventQueueAdapter");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.8",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"@koa/cors": "^5.0.0",
|
|
11
11
|
"@koa/multer": "^3.1.0",
|
|
12
12
|
"@koa/router": "^13.1.0",
|
|
13
|
-
"@nocobase/acl": "1.8.
|
|
14
|
-
"@nocobase/actions": "1.8.
|
|
15
|
-
"@nocobase/auth": "1.8.
|
|
16
|
-
"@nocobase/cache": "1.8.
|
|
17
|
-
"@nocobase/data-source-manager": "1.8.
|
|
18
|
-
"@nocobase/database": "1.8.
|
|
19
|
-
"@nocobase/evaluators": "1.8.
|
|
20
|
-
"@nocobase/lock-manager": "1.8.
|
|
21
|
-
"@nocobase/logger": "1.8.
|
|
22
|
-
"@nocobase/resourcer": "1.8.
|
|
23
|
-
"@nocobase/sdk": "1.8.
|
|
24
|
-
"@nocobase/telemetry": "1.8.
|
|
25
|
-
"@nocobase/utils": "1.8.
|
|
13
|
+
"@nocobase/acl": "1.8.8",
|
|
14
|
+
"@nocobase/actions": "1.8.8",
|
|
15
|
+
"@nocobase/auth": "1.8.8",
|
|
16
|
+
"@nocobase/cache": "1.8.8",
|
|
17
|
+
"@nocobase/data-source-manager": "1.8.8",
|
|
18
|
+
"@nocobase/database": "1.8.8",
|
|
19
|
+
"@nocobase/evaluators": "1.8.8",
|
|
20
|
+
"@nocobase/lock-manager": "1.8.8",
|
|
21
|
+
"@nocobase/logger": "1.8.8",
|
|
22
|
+
"@nocobase/resourcer": "1.8.8",
|
|
23
|
+
"@nocobase/sdk": "1.8.8",
|
|
24
|
+
"@nocobase/telemetry": "1.8.8",
|
|
25
|
+
"@nocobase/utils": "1.8.8",
|
|
26
26
|
"@types/decompress": "4.2.7",
|
|
27
27
|
"@types/ini": "^1.3.31",
|
|
28
28
|
"@types/koa-send": "^4.1.3",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"@types/serve-handler": "^6.1.1",
|
|
58
58
|
"@types/ws": "^8.5.5"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "33a6e5154a9b6b2ffe1a7919b91f23304e97c5c5"
|
|
61
61
|
}
|