@nocobase/server 2.0.0-alpha.40 → 2.0.0-alpha.42
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 +0 -3
- package/lib/application.js +0 -3
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -2
- package/package.json +16 -16
- package/lib/background-job-manager.d.ts +0 -40
- package/lib/background-job-manager.js +0 -111
package/lib/application.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ import { PubSubManager, PubSubManagerOptions } from './pub-sub-manager';
|
|
|
33
33
|
import { SyncMessageManager } from './sync-message-manager';
|
|
34
34
|
import AesEncryptor from './aes-encryptor';
|
|
35
35
|
import { AuditManager } from './audit-manager';
|
|
36
|
-
import { BackgroundJobManager, BackgroundJobManagerOptions } from './background-job-manager';
|
|
37
36
|
import { Environment } from './environment';
|
|
38
37
|
import { EventQueue, EventQueueOptions } from './event-queue';
|
|
39
38
|
import { RedisConfig, RedisConnectionManager } from './redis-connection-manager';
|
|
@@ -89,7 +88,6 @@ export interface ApplicationOptions {
|
|
|
89
88
|
auditManager?: AuditManager;
|
|
90
89
|
lockManager?: LockManagerOptions;
|
|
91
90
|
eventQueue?: EventQueueOptions;
|
|
92
|
-
backgroundJobManager?: BackgroundJobManagerOptions;
|
|
93
91
|
/**
|
|
94
92
|
* @internal
|
|
95
93
|
*/
|
|
@@ -190,7 +188,6 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
190
188
|
container: ServiceContainer;
|
|
191
189
|
lockManager: LockManager;
|
|
192
190
|
eventQueue: EventQueue;
|
|
193
|
-
backgroundJobManager: BackgroundJobManager;
|
|
194
191
|
constructor(options: ApplicationOptions);
|
|
195
192
|
private static staticCommands;
|
|
196
193
|
static registerStaticCommand(callback: (app: Application) => void): void;
|
package/lib/application.js
CHANGED
|
@@ -80,7 +80,6 @@ var import_package = __toESM(require("../package.json"));
|
|
|
80
80
|
var import_available_action = require("./acl/available-action");
|
|
81
81
|
var import_aes_encryptor = __toESM(require("./aes-encryptor"));
|
|
82
82
|
var import_audit_manager = require("./audit-manager");
|
|
83
|
-
var import_background_job_manager = require("./background-job-manager");
|
|
84
83
|
var import_environment = require("./environment");
|
|
85
84
|
var import_event_queue = require("./event-queue");
|
|
86
85
|
var import_redis_connection_manager = require("./redis-connection-manager");
|
|
@@ -142,7 +141,6 @@ const _Application = class _Application extends import_koa.default {
|
|
|
142
141
|
container = new import_service_container.ServiceContainer();
|
|
143
142
|
lockManager;
|
|
144
143
|
eventQueue;
|
|
145
|
-
backgroundJobManager;
|
|
146
144
|
static registerStaticCommand(callback) {
|
|
147
145
|
this.staticCommands.push(callback);
|
|
148
146
|
}
|
|
@@ -922,7 +920,6 @@ const _Application = class _Application extends import_koa.default {
|
|
|
922
920
|
this.pubSubManager = (0, import_pub_sub_manager.createPubSubManager)(this, options.pubSubManager);
|
|
923
921
|
this.syncMessageManager = new import_sync_message_manager.SyncMessageManager(this, options.syncMessageManager);
|
|
924
922
|
this.eventQueue = new import_event_queue.EventQueue(this, options.eventQueue);
|
|
925
|
-
this.backgroundJobManager = new import_background_job_manager.BackgroundJobManager(this, options.backgroundJobManager);
|
|
926
923
|
this.lockManager = new import_lock_manager.LockManager({
|
|
927
924
|
defaultAdapter: process.env.LOCK_ADAPTER_DEFAULT,
|
|
928
925
|
...options.lockManager
|
package/lib/index.d.ts
CHANGED
|
@@ -19,7 +19,6 @@ export * from './plugin';
|
|
|
19
19
|
export * from './plugin-manager';
|
|
20
20
|
export * from './pub-sub-manager';
|
|
21
21
|
export * from './event-queue';
|
|
22
|
-
export * from './background-job-manager';
|
|
23
22
|
export * from './worker-id-allocator';
|
|
24
23
|
export * from './redis-connection-manager';
|
|
25
24
|
export * from './main-data-source';
|
package/lib/index.js
CHANGED
|
@@ -61,7 +61,6 @@ __reExport(src_exports, require("./plugin"), module.exports);
|
|
|
61
61
|
__reExport(src_exports, require("./plugin-manager"), module.exports);
|
|
62
62
|
__reExport(src_exports, require("./pub-sub-manager"), module.exports);
|
|
63
63
|
__reExport(src_exports, require("./event-queue"), module.exports);
|
|
64
|
-
__reExport(src_exports, require("./background-job-manager"), module.exports);
|
|
65
64
|
__reExport(src_exports, require("./worker-id-allocator"), module.exports);
|
|
66
65
|
__reExport(src_exports, require("./redis-connection-manager"), module.exports);
|
|
67
66
|
__reExport(src_exports, require("./main-data-source"), module.exports);
|
|
@@ -89,7 +88,6 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
|
89
88
|
...require("./plugin-manager"),
|
|
90
89
|
...require("./pub-sub-manager"),
|
|
91
90
|
...require("./event-queue"),
|
|
92
|
-
...require("./background-job-manager"),
|
|
93
91
|
...require("./worker-id-allocator"),
|
|
94
92
|
...require("./redis-connection-manager"),
|
|
95
93
|
...require("./main-data-source")
|
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.42",
|
|
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.42",
|
|
14
|
+
"@nocobase/actions": "2.0.0-alpha.42",
|
|
15
|
+
"@nocobase/auth": "2.0.0-alpha.42",
|
|
16
|
+
"@nocobase/cache": "2.0.0-alpha.42",
|
|
17
|
+
"@nocobase/data-source-manager": "2.0.0-alpha.42",
|
|
18
|
+
"@nocobase/database": "2.0.0-alpha.42",
|
|
19
|
+
"@nocobase/evaluators": "2.0.0-alpha.42",
|
|
20
|
+
"@nocobase/lock-manager": "2.0.0-alpha.42",
|
|
21
|
+
"@nocobase/logger": "2.0.0-alpha.42",
|
|
22
|
+
"@nocobase/resourcer": "2.0.0-alpha.42",
|
|
23
|
+
"@nocobase/sdk": "2.0.0-alpha.42",
|
|
24
|
+
"@nocobase/snowflake-id": "2.0.0-alpha.42",
|
|
25
|
+
"@nocobase/telemetry": "2.0.0-alpha.42",
|
|
26
|
+
"@nocobase/utils": "2.0.0-alpha.42",
|
|
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": "9e96dd78d0c1445c8da76863e30f046be5b48d90"
|
|
64
64
|
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
import Application from './application';
|
|
10
|
-
import { QueueEventOptions, QueueMessageOptions } from './event-queue';
|
|
11
|
-
export interface BackgroundJobManagerOptions {
|
|
12
|
-
channel?: string;
|
|
13
|
-
}
|
|
14
|
-
type BackgroundJobEventOptions = Pick<QueueEventOptions, 'process' | 'idle'>;
|
|
15
|
-
declare class BackgroundJobManager {
|
|
16
|
-
private app;
|
|
17
|
-
private options;
|
|
18
|
-
static DEFAULT_CHANNEL: string;
|
|
19
|
-
private subscriptions;
|
|
20
|
-
private processing;
|
|
21
|
-
private get channel();
|
|
22
|
-
private onAfterStart;
|
|
23
|
-
private onBeforeStop;
|
|
24
|
-
private process;
|
|
25
|
-
constructor(app: Application, options?: BackgroundJobManagerOptions);
|
|
26
|
-
private get idle();
|
|
27
|
-
/**
|
|
28
|
-
* 订阅指定主题的任务处理器
|
|
29
|
-
* @param options 订阅选项
|
|
30
|
-
*/
|
|
31
|
-
subscribe(topic: string, options: BackgroundJobEventOptions): void;
|
|
32
|
-
/**
|
|
33
|
-
* 取消订阅指定主题
|
|
34
|
-
* @param topic 主题名称
|
|
35
|
-
*/
|
|
36
|
-
unsubscribe(topic: string): void;
|
|
37
|
-
publish(topic: string, payload: any, options?: QueueMessageOptions): Promise<void>;
|
|
38
|
-
}
|
|
39
|
-
export { BackgroundJobManager };
|
|
40
|
-
export default BackgroundJobManager;
|
|
@@ -1,111 +0,0 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
30
|
-
var background_job_manager_exports = {};
|
|
31
|
-
__export(background_job_manager_exports, {
|
|
32
|
-
BackgroundJobManager: () => BackgroundJobManager,
|
|
33
|
-
default: () => background_job_manager_default
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(background_job_manager_exports);
|
|
36
|
-
const _BackgroundJobManager = class _BackgroundJobManager {
|
|
37
|
-
constructor(app, options = {}) {
|
|
38
|
-
this.app = app;
|
|
39
|
-
this.options = options;
|
|
40
|
-
this.app.on("afterStart", this.onAfterStart);
|
|
41
|
-
this.app.on("beforeStop", this.onBeforeStop);
|
|
42
|
-
}
|
|
43
|
-
subscriptions = /* @__PURE__ */ new Map();
|
|
44
|
-
// topic -> handler
|
|
45
|
-
processing = null;
|
|
46
|
-
get channel() {
|
|
47
|
-
return this.options.channel ?? _BackgroundJobManager.DEFAULT_CHANNEL;
|
|
48
|
-
}
|
|
49
|
-
onAfterStart = /* @__PURE__ */ __name(() => {
|
|
50
|
-
this.app.eventQueue.subscribe(this.channel, {
|
|
51
|
-
idle: /* @__PURE__ */ __name(() => this.idle, "idle"),
|
|
52
|
-
process: this.process
|
|
53
|
-
});
|
|
54
|
-
}, "onAfterStart");
|
|
55
|
-
onBeforeStop = /* @__PURE__ */ __name(() => {
|
|
56
|
-
this.app.eventQueue.unsubscribe(this.channel);
|
|
57
|
-
}, "onBeforeStop");
|
|
58
|
-
process = /* @__PURE__ */ __name(async ({ topic, payload }, options) => {
|
|
59
|
-
const event = this.subscriptions.get(topic);
|
|
60
|
-
if (!event) {
|
|
61
|
-
this.app.logger.warn(`No handler found for topic: ${topic}, event skipped.`);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this.processing = event.process(payload, options);
|
|
65
|
-
try {
|
|
66
|
-
await this.processing;
|
|
67
|
-
this.app.logger.debug(`Completed background job ${topic}:${options.id}`);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
this.app.logger.error(`Failed to process background job ${topic}:${options.id}`, error);
|
|
70
|
-
throw error;
|
|
71
|
-
} finally {
|
|
72
|
-
this.processing = null;
|
|
73
|
-
}
|
|
74
|
-
}, "process");
|
|
75
|
-
get idle() {
|
|
76
|
-
return !this.processing && [...this.subscriptions.values()].every((event) => event.idle());
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* 订阅指定主题的任务处理器
|
|
80
|
-
* @param options 订阅选项
|
|
81
|
-
*/
|
|
82
|
-
subscribe(topic, options) {
|
|
83
|
-
if (this.subscriptions.has(topic)) {
|
|
84
|
-
this.app.logger.warn(`Topic "${topic}" already has a handler, skip...`);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this.subscriptions.set(topic, options);
|
|
88
|
-
this.app.logger.debug(`Subscribed to background job topic: ${topic}`);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 取消订阅指定主题
|
|
92
|
-
* @param topic 主题名称
|
|
93
|
-
*/
|
|
94
|
-
unsubscribe(topic) {
|
|
95
|
-
if (this.subscriptions.has(topic)) {
|
|
96
|
-
this.subscriptions.delete(topic);
|
|
97
|
-
this.app.logger.debug(`Unsubscribed from background job topic: ${topic}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async publish(topic, payload, options) {
|
|
101
|
-
await this.app.eventQueue.publish(this.channel, { topic, payload }, options);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
__name(_BackgroundJobManager, "BackgroundJobManager");
|
|
105
|
-
__publicField(_BackgroundJobManager, "DEFAULT_CHANNEL", "background-jobs");
|
|
106
|
-
let BackgroundJobManager = _BackgroundJobManager;
|
|
107
|
-
var background_job_manager_default = BackgroundJobManager;
|
|
108
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
-
0 && (module.exports = {
|
|
110
|
-
BackgroundJobManager
|
|
111
|
-
});
|