@nocobase/server 2.1.0-beta.11 → 2.1.0-beta.12
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/app-supervisor/index.js +13 -2
- package/lib/application.d.ts +1 -2
- package/lib/application.js +3 -24
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/pub-sub-manager/handler-manager.d.ts +1 -0
- package/lib/pub-sub-manager/handler-manager.js +11 -0
- package/lib/pub-sub-manager/pub-sub-manager.js +2 -1
- package/lib/sync-message-manager.js +8 -1
- package/lib/worker-mode.d.ts +19 -0
- package/lib/worker-mode.js +67 -0
- package/package.json +17 -17
|
@@ -47,6 +47,7 @@ var import_lodash = __toESM(require("lodash"));
|
|
|
47
47
|
var import_utils = require("@nocobase/utils");
|
|
48
48
|
var import_events = require("events");
|
|
49
49
|
var import_application = __toESM(require("../application"));
|
|
50
|
+
var import_worker_mode = require("../worker-mode");
|
|
50
51
|
var import_main_only_adapter = require("./main-only-adapter");
|
|
51
52
|
var import_handler = require("../errors/handler");
|
|
52
53
|
var import_condition_registry = require("./condition-registry");
|
|
@@ -288,6 +289,10 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
288
289
|
return this.discoveryAdapter.getAppStatus(appName, defaultStatus);
|
|
289
290
|
}
|
|
290
291
|
async setAppStatus(appName, status, options = {}) {
|
|
292
|
+
if ((0, import_worker_mode.isTransient)()) {
|
|
293
|
+
this.logger.debug("App running as worker, status will not be set", { appName, status });
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
291
296
|
this.logger.debug("Setting app status", { appName, status });
|
|
292
297
|
return this.discoveryAdapter.setAppStatus(appName, status, options);
|
|
293
298
|
}
|
|
@@ -329,7 +334,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
329
334
|
};
|
|
330
335
|
}
|
|
331
336
|
const app = new import_application.default(options);
|
|
332
|
-
if (hook ??
|
|
337
|
+
if (hook ?? !(0, import_worker_mode.isTransient)()) {
|
|
333
338
|
app.on("afterStart", async () => {
|
|
334
339
|
await this.sendSyncMessage(mainApp, {
|
|
335
340
|
type: "app:started",
|
|
@@ -356,6 +361,9 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
356
361
|
this.registerCommandHandler(app);
|
|
357
362
|
app.on("afterStart", async (app2) => {
|
|
358
363
|
var _a, _b;
|
|
364
|
+
if ((0, import_worker_mode.isTransient)()) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
359
367
|
await app2.syncMessageManager.subscribe(
|
|
360
368
|
"app_supervisor:sync",
|
|
361
369
|
async (message) => {
|
|
@@ -390,6 +398,9 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
390
398
|
}
|
|
391
399
|
});
|
|
392
400
|
app.on("afterDestroy", async (app2) => {
|
|
401
|
+
if ((0, import_worker_mode.isTransient)()) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
393
404
|
await this.unregisterEnvironment();
|
|
394
405
|
});
|
|
395
406
|
return app;
|
|
@@ -586,7 +597,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
586
597
|
return super.on(eventName, listener);
|
|
587
598
|
}
|
|
588
599
|
bindAppEvents(app) {
|
|
589
|
-
if (
|
|
600
|
+
if ((0, import_worker_mode.isTransient)()) {
|
|
590
601
|
return;
|
|
591
602
|
}
|
|
592
603
|
app.on("afterDestroy", async () => {
|
package/lib/application.d.ts
CHANGED
|
@@ -270,8 +270,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
270
270
|
protected _aesEncryptor: AesEncryptor;
|
|
271
271
|
get aesEncryptor(): AesEncryptor;
|
|
272
272
|
/**
|
|
273
|
-
*
|
|
274
|
-
* @experimental
|
|
273
|
+
* @deprecated use {@link serving} from './worker-mode' instead.
|
|
275
274
|
*/
|
|
276
275
|
serving(key?: string): boolean;
|
|
277
276
|
/**
|
package/lib/application.js
CHANGED
|
@@ -87,6 +87,7 @@ var import_redis_connection_manager = require("./redis-connection-manager");
|
|
|
87
87
|
var import_service_container = require("./service-container");
|
|
88
88
|
var import_snowflake_id_field = require("./snowflake-id-field");
|
|
89
89
|
var import_worker_id_allocator = require("./worker-id-allocator");
|
|
90
|
+
var import_worker_mode = require("./worker-mode");
|
|
90
91
|
const _Application = class _Application extends import_koa.default {
|
|
91
92
|
constructor(options) {
|
|
92
93
|
super();
|
|
@@ -282,32 +283,10 @@ const _Application = class _Application extends import_koa.default {
|
|
|
282
283
|
return this._aesEncryptor;
|
|
283
284
|
}
|
|
284
285
|
/**
|
|
285
|
-
*
|
|
286
|
-
* @experimental
|
|
286
|
+
* @deprecated use {@link serving} from './worker-mode' instead.
|
|
287
287
|
*/
|
|
288
288
|
serving(key) {
|
|
289
|
-
|
|
290
|
-
if (!WORKER_MODE) {
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
if (WORKER_MODE === "-") {
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
const topics = WORKER_MODE.trim().split(",");
|
|
297
|
-
if (key) {
|
|
298
|
-
if (WORKER_MODE === "*") {
|
|
299
|
-
return true;
|
|
300
|
-
}
|
|
301
|
-
if (topics.includes(key)) {
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
|
-
return false;
|
|
305
|
-
} else {
|
|
306
|
-
if (topics.includes("!")) {
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
289
|
+
return (0, import_worker_mode.serving)(key);
|
|
311
290
|
}
|
|
312
291
|
/**
|
|
313
292
|
* @internal
|
package/lib/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './plugin-manager';
|
|
|
20
20
|
export * from './pub-sub-manager';
|
|
21
21
|
export * from './event-queue';
|
|
22
22
|
export * from './worker-id-allocator';
|
|
23
|
+
export * from './worker-mode';
|
|
23
24
|
export * from './redis-connection-manager';
|
|
24
25
|
export * from './main-data-source';
|
|
25
26
|
export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
package/lib/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __reExport(src_exports, require("./plugin-manager"), module.exports);
|
|
|
63
63
|
__reExport(src_exports, require("./pub-sub-manager"), module.exports);
|
|
64
64
|
__reExport(src_exports, require("./event-queue"), module.exports);
|
|
65
65
|
__reExport(src_exports, require("./worker-id-allocator"), module.exports);
|
|
66
|
+
__reExport(src_exports, require("./worker-mode"), module.exports);
|
|
66
67
|
__reExport(src_exports, require("./redis-connection-manager"), module.exports);
|
|
67
68
|
__reExport(src_exports, require("./main-data-source"), module.exports);
|
|
68
69
|
var import_findPackageNames = require("./plugin-manager/findPackageNames");
|
|
@@ -92,6 +93,7 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
|
92
93
|
...require("./pub-sub-manager"),
|
|
93
94
|
...require("./event-queue"),
|
|
94
95
|
...require("./worker-id-allocator"),
|
|
96
|
+
...require("./worker-mode"),
|
|
95
97
|
...require("./redis-connection-manager"),
|
|
96
98
|
...require("./main-data-source")
|
|
97
99
|
});
|
|
@@ -29,6 +29,7 @@ export declare class HandlerManager {
|
|
|
29
29
|
set(channel: string, callback: any, options: PubSubManagerSubscribeOptions): (wrappedMessage: any) => Promise<void>;
|
|
30
30
|
get(channel: string, callback: any): any;
|
|
31
31
|
delete(channel: string, callback: any): any;
|
|
32
|
+
cancelPendingDebounce(): void;
|
|
32
33
|
reset(): void;
|
|
33
34
|
each(callback: any): Promise<void>;
|
|
34
35
|
}
|
|
@@ -129,7 +129,18 @@ const _HandlerManager = class _HandlerManager {
|
|
|
129
129
|
headlerMap.delete(callback);
|
|
130
130
|
return headler;
|
|
131
131
|
}
|
|
132
|
+
cancelPendingDebounce() {
|
|
133
|
+
if (this.uniqueMessageHandlers) {
|
|
134
|
+
for (const handler of this.uniqueMessageHandlers.values()) {
|
|
135
|
+
if (typeof (handler == null ? void 0 : handler.cancel) === "function") {
|
|
136
|
+
handler.cancel();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.uniqueMessageHandlers.clear();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
132
142
|
reset() {
|
|
143
|
+
this.cancelPendingDebounce();
|
|
133
144
|
this.handlers = /* @__PURE__ */ new Map();
|
|
134
145
|
this.uniqueMessageHandlers = /* @__PURE__ */ new Map();
|
|
135
146
|
}
|
|
@@ -38,7 +38,7 @@ const createPubSubManager = /* @__PURE__ */ __name((app, options) => {
|
|
|
38
38
|
app.on("afterStart", async () => {
|
|
39
39
|
await pubSubManager.connect();
|
|
40
40
|
});
|
|
41
|
-
app.on("
|
|
41
|
+
app.on("beforeStop", async () => {
|
|
42
42
|
await pubSubManager.close();
|
|
43
43
|
});
|
|
44
44
|
return pubSubManager;
|
|
@@ -77,6 +77,7 @@ const _PubSubManager = class _PubSubManager {
|
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
async close() {
|
|
80
|
+
this.handlerManager.cancelPendingDebounce();
|
|
80
81
|
if (!this.adapter) {
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
@@ -40,7 +40,14 @@ const _SyncMessageManager = class _SyncMessageManager {
|
|
|
40
40
|
if (!plugin.name) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
if (typeof plugin.handleSyncMessage === "function") {
|
|
44
|
+
await this.subscribe(plugin.name, async (...args) => {
|
|
45
|
+
if (app.stopped || app.db.closed()) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
return plugin.handleSyncMessage(...args);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
53
|
versionManager;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Check if the application is running in transient mode (WORKER_MODE === '-'),
|
|
11
|
+
* which means it is a short-lived subprocess spawned to execute a command and then exit.
|
|
12
|
+
* @experimental
|
|
13
|
+
*/
|
|
14
|
+
export declare function isTransient(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Check if the application is serving as a specific worker.
|
|
17
|
+
* @experimental
|
|
18
|
+
*/
|
|
19
|
+
export declare function serving(key?: string): boolean;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var worker_mode_exports = {};
|
|
29
|
+
__export(worker_mode_exports, {
|
|
30
|
+
isTransient: () => isTransient,
|
|
31
|
+
serving: () => serving
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(worker_mode_exports);
|
|
34
|
+
function isTransient() {
|
|
35
|
+
return process.env.WORKER_MODE === "-";
|
|
36
|
+
}
|
|
37
|
+
__name(isTransient, "isTransient");
|
|
38
|
+
function serving(key) {
|
|
39
|
+
const { WORKER_MODE = "" } = process.env;
|
|
40
|
+
if (!WORKER_MODE) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (WORKER_MODE === "-") {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const topics = WORKER_MODE.trim().split(",");
|
|
47
|
+
if (key) {
|
|
48
|
+
if (WORKER_MODE === "*") {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (topics.includes(key)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
} else {
|
|
56
|
+
if (topics.includes("!")) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
__name(serving, "serving");
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
isTransient,
|
|
66
|
+
serving
|
|
67
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.12",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,21 +10,21 @@
|
|
|
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.1.0-beta.
|
|
14
|
-
"@nocobase/actions": "2.1.0-beta.
|
|
15
|
-
"@nocobase/ai": "2.1.0-beta.
|
|
16
|
-
"@nocobase/auth": "2.1.0-beta.
|
|
17
|
-
"@nocobase/cache": "2.1.0-beta.
|
|
18
|
-
"@nocobase/data-source-manager": "2.1.0-beta.
|
|
19
|
-
"@nocobase/database": "2.1.0-beta.
|
|
20
|
-
"@nocobase/evaluators": "2.1.0-beta.
|
|
21
|
-
"@nocobase/lock-manager": "2.1.0-beta.
|
|
22
|
-
"@nocobase/logger": "2.1.0-beta.
|
|
23
|
-
"@nocobase/resourcer": "2.1.0-beta.
|
|
24
|
-
"@nocobase/sdk": "2.1.0-beta.
|
|
25
|
-
"@nocobase/snowflake-id": "2.1.0-beta.
|
|
26
|
-
"@nocobase/telemetry": "2.1.0-beta.
|
|
27
|
-
"@nocobase/utils": "2.1.0-beta.
|
|
13
|
+
"@nocobase/acl": "2.1.0-beta.12",
|
|
14
|
+
"@nocobase/actions": "2.1.0-beta.12",
|
|
15
|
+
"@nocobase/ai": "2.1.0-beta.12",
|
|
16
|
+
"@nocobase/auth": "2.1.0-beta.12",
|
|
17
|
+
"@nocobase/cache": "2.1.0-beta.12",
|
|
18
|
+
"@nocobase/data-source-manager": "2.1.0-beta.12",
|
|
19
|
+
"@nocobase/database": "2.1.0-beta.12",
|
|
20
|
+
"@nocobase/evaluators": "2.1.0-beta.12",
|
|
21
|
+
"@nocobase/lock-manager": "2.1.0-beta.12",
|
|
22
|
+
"@nocobase/logger": "2.1.0-beta.12",
|
|
23
|
+
"@nocobase/resourcer": "2.1.0-beta.12",
|
|
24
|
+
"@nocobase/sdk": "2.1.0-beta.12",
|
|
25
|
+
"@nocobase/snowflake-id": "2.1.0-beta.12",
|
|
26
|
+
"@nocobase/telemetry": "2.1.0-beta.12",
|
|
27
|
+
"@nocobase/utils": "2.1.0-beta.12",
|
|
28
28
|
"@types/decompress": "4.2.7",
|
|
29
29
|
"@types/ini": "^1.3.31",
|
|
30
30
|
"@types/koa-send": "^4.1.3",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"@types/serve-handler": "^6.1.1",
|
|
62
62
|
"@types/ws": "^8.5.5"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "25cee9643f42f850afc4adc33c55a56850ac730d"
|
|
65
65
|
}
|