@nocobase/server 1.8.23 → 1.8.24

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.
@@ -7,6 +7,7 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import Application from './application';
10
+ import { SystemLogger } from '@nocobase/logger';
10
11
  export declare const QUEUE_DEFAULT_INTERVAL = 250;
11
12
  export declare const QUEUE_DEFAULT_CONCURRENCY = 1;
12
13
  export declare const QUEUE_DEFAULT_ACK_TIMEOUT = 15000;
@@ -58,6 +59,7 @@ export declare class MemoryEventQueueAdapter implements IEventQueueAdapter {
58
59
  listen: (channel: string) => void;
59
60
  constructor(options: {
60
61
  appName: string;
62
+ logger: SystemLogger;
61
63
  });
62
64
  isConnected(): boolean;
63
65
  setConnected(connected: boolean): void;
@@ -77,9 +77,10 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
77
77
  if (!this.connected) {
78
78
  return;
79
79
  }
80
+ const { logger } = this.options;
80
81
  const event = this.events.get(channel);
81
82
  if (!event) {
82
- console.warn(`memory queue (${channel}) not found, skipping...`);
83
+ logger.warn(`memory queue (${channel}) not found, skipping...`);
83
84
  return;
84
85
  }
85
86
  if (!event.idle()) {
@@ -88,12 +89,9 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
88
89
  const reading = this.reading.get(channel) || [];
89
90
  const count = (event.concurrency || QUEUE_DEFAULT_CONCURRENCY) - reading.length;
90
91
  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
92
  return;
95
93
  }
96
- console.debug(`reading more from queue (${channel}), count: ${count}`);
94
+ logger.debug(`reading more from queue (${channel}), count: ${count}`);
97
95
  this.read(channel, count).forEach((promise) => {
98
96
  reading.push(promise);
99
97
  promise.finally(() => {
@@ -114,20 +112,21 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
114
112
  async loadFromStorage() {
115
113
  let queues = {};
116
114
  let exists = false;
115
+ const { logger } = this.options;
117
116
  try {
118
117
  await import_promises.default.stat(this.storagePath);
119
118
  exists = true;
120
119
  } catch (ex) {
121
- console.info(`memory queue storage file not found, skip`);
120
+ logger.info(`memory queue storage file not found, skip`);
122
121
  }
123
122
  if (exists) {
124
123
  try {
125
124
  const queueJson = await import_promises.default.readFile(this.storagePath);
126
125
  queues = JSON.parse(queueJson.toString());
127
- console.debug("memory queue loaded from storage", queues);
126
+ logger.debug("memory queue loaded from storage", queues);
128
127
  await import_promises.default.unlink(this.storagePath);
129
128
  } catch (ex) {
130
- console.error("failed to load queue from storage", ex);
129
+ logger.error("failed to load queue from storage", ex);
131
130
  }
132
131
  }
133
132
  this.queues = new Map(Object.entries(queues));
@@ -139,12 +138,13 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
139
138
  }
140
139
  return acc;
141
140
  }, {});
141
+ const { logger } = this.options;
142
142
  if (Object.keys(queues).length) {
143
143
  await import_promises.default.mkdir(import_path.default.dirname(this.storagePath), { recursive: true });
144
144
  await import_promises.default.writeFile(this.storagePath, JSON.stringify(queues));
145
- console.debug("memory queue saved to storage", queues);
145
+ logger.debug("memory queue saved to storage", queues);
146
146
  } else {
147
- console.debug("memory queue empty, no need to save to storage");
147
+ logger.debug("memory queue empty, no need to save to storage");
148
148
  }
149
149
  }
150
150
  async connect() {
@@ -163,13 +163,14 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
163
163
  if (!this.connected) {
164
164
  return;
165
165
  }
166
+ const { logger } = this.options;
166
167
  this.connected = false;
167
168
  if (this.processing) {
168
- console.info("memory queue waiting for processing job...");
169
+ logger.info("memory queue waiting for processing job...");
169
170
  await this.processing;
170
- console.info("memory queue job cleaned");
171
+ logger.info("memory queue job cleaned");
171
172
  }
172
- console.log("memory queue gracefully shutting down...");
173
+ logger.info("memory queue gracefully shutting down...");
173
174
  await this.saveToStorage();
174
175
  }
175
176
  subscribe(channel, options) {
@@ -203,7 +204,8 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
203
204
  const queue = this.queues.get(channel);
204
205
  const message = { id: (0, import_crypto.randomUUID)(), content, options };
205
206
  queue.push(message);
206
- console.debug(`memory queue (${channel}) published message`, content);
207
+ const { logger } = this.options;
208
+ logger.debug(`memory queue (${channel}) published message`, content);
207
209
  setImmediate(() => {
208
210
  this.emitter.emit(channel, channel);
209
211
  });
@@ -227,8 +229,9 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
227
229
  if (!(queue == null ? void 0 : queue.length)) {
228
230
  return [];
229
231
  }
232
+ const { logger } = this.options;
230
233
  const messages = queue.slice(0, n);
231
- console.debug(`memory queue (${channel}) read ${messages.length} messages`, messages);
234
+ logger.debug(`memory queue (${channel}) read ${messages.length} messages`, messages);
232
235
  queue.splice(0, messages.length);
233
236
  const batch = messages.map(({ id, ...message }) => this.process(channel, { id, message }));
234
237
  return batch;
@@ -236,17 +239,18 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
236
239
  async process(channel, { id, message }) {
237
240
  const event = this.events.get(channel);
238
241
  const { content, options: { timeout = QUEUE_DEFAULT_ACK_TIMEOUT, maxRetries = 0, retried = 0 } = {} } = message;
239
- console.debug(`memory queue (${channel}) processing message (${id})...`, content);
242
+ const { logger } = this.options;
243
+ logger.debug(`memory queue (${channel}) processing message (${id})...`, content);
240
244
  return (async () => event.process(content, {
241
245
  id,
242
246
  retried,
243
247
  signal: AbortSignal.timeout(timeout)
244
248
  }))().then(() => {
245
- console.debug(`memory queue (${channel}) consumed message (${id})`);
249
+ logger.debug(`memory queue (${channel}) consumed message (${id})`);
246
250
  }).catch((ex) => {
247
251
  if (maxRetries > 0 && retried < maxRetries) {
248
252
  const currentRetry = retried + 1;
249
- console.warn(
253
+ logger.warn(
250
254
  `memory queue (${channel}) consum message (${id}) failed, retrying (${currentRetry} / ${maxRetries})...`,
251
255
  ex
252
256
  );
@@ -254,7 +258,7 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
254
258
  this.publish(channel, content, { timeout, maxRetries, retried: currentRetry, timestamp: Date.now() });
255
259
  }, 500);
256
260
  } else {
257
- console.error(ex);
261
+ logger.error(ex);
258
262
  }
259
263
  });
260
264
  }
@@ -265,7 +269,7 @@ const _EventQueue = class _EventQueue {
265
269
  constructor(app, options = {}) {
266
270
  this.app = app;
267
271
  this.options = options;
268
- this.setAdapter(new MemoryEventQueueAdapter({ appName: this.app.name }));
272
+ this.setAdapter(new MemoryEventQueueAdapter({ appName: this.app.name, logger: this.app.logger }));
269
273
  app.on("afterStart", async () => {
270
274
  await this.connect();
271
275
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "1.8.23",
3
+ "version": "1.8.24",
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.23",
14
- "@nocobase/actions": "1.8.23",
15
- "@nocobase/auth": "1.8.23",
16
- "@nocobase/cache": "1.8.23",
17
- "@nocobase/data-source-manager": "1.8.23",
18
- "@nocobase/database": "1.8.23",
19
- "@nocobase/evaluators": "1.8.23",
20
- "@nocobase/lock-manager": "1.8.23",
21
- "@nocobase/logger": "1.8.23",
22
- "@nocobase/resourcer": "1.8.23",
23
- "@nocobase/sdk": "1.8.23",
24
- "@nocobase/telemetry": "1.8.23",
25
- "@nocobase/utils": "1.8.23",
13
+ "@nocobase/acl": "1.8.24",
14
+ "@nocobase/actions": "1.8.24",
15
+ "@nocobase/auth": "1.8.24",
16
+ "@nocobase/cache": "1.8.24",
17
+ "@nocobase/data-source-manager": "1.8.24",
18
+ "@nocobase/database": "1.8.24",
19
+ "@nocobase/evaluators": "1.8.24",
20
+ "@nocobase/lock-manager": "1.8.24",
21
+ "@nocobase/logger": "1.8.24",
22
+ "@nocobase/resourcer": "1.8.24",
23
+ "@nocobase/sdk": "1.8.24",
24
+ "@nocobase/telemetry": "1.8.24",
25
+ "@nocobase/utils": "1.8.24",
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": "e5d7668cd760e281f9d1eeca6828ea2bc866bbae"
60
+ "gitHead": "e3907742d0f42d21943f7807bb254838fafd5fff"
61
61
  }