@eggjs/cluster 4.0.0-beta.34 → 4.0.0-beta.36

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.
Files changed (35) hide show
  1. package/dist/agent_worker.d.ts +1 -1
  2. package/dist/agent_worker.js +50 -65
  3. package/dist/app_worker.d.ts +1 -1
  4. package/dist/app_worker.js +127 -165
  5. package/dist/error/ClusterAgentWorkerError.d.ts +12 -9
  6. package/dist/error/ClusterAgentWorkerError.js +22 -19
  7. package/dist/error/ClusterWorkerExceptionError.d.ts +9 -6
  8. package/dist/error/ClusterWorkerExceptionError.js +17 -14
  9. package/dist/index.d.ts +20 -15
  10. package/dist/index.js +20 -16
  11. package/dist/master.d.ts +89 -86
  12. package/dist/master.js +425 -556
  13. package/dist/utils/messenger.d.ts +93 -89
  14. package/dist/utils/messenger.js +143 -178
  15. package/dist/utils/mode/base/agent.d.ts +42 -35
  16. package/dist/utils/mode/base/agent.js +63 -65
  17. package/dist/utils/mode/base/app.d.ts +53 -45
  18. package/dist/utils/mode/base/app.js +77 -80
  19. package/dist/utils/mode/impl/process/agent.d.ts +20 -16
  20. package/dist/utils/mode/impl/process/agent.js +95 -105
  21. package/dist/utils/mode/impl/process/app.d.ts +23 -19
  22. package/dist/utils/mode/impl/process/app.js +116 -118
  23. package/dist/utils/mode/impl/worker_threads/agent.d.ts +20 -16
  24. package/dist/utils/mode/impl/worker_threads/agent.js +78 -85
  25. package/dist/utils/mode/impl/worker_threads/app.d.ts +28 -24
  26. package/dist/utils/mode/impl/worker_threads/app.js +128 -137
  27. package/dist/utils/options.d.ts +79 -76
  28. package/dist/utils/options.js +55 -80
  29. package/dist/utils/terminate.js +50 -70
  30. package/dist/utils/worker_manager.d.ts +28 -24
  31. package/dist/utils/worker_manager.js +68 -74
  32. package/package.json +33 -34
  33. package/dist/error/index.d.ts +0 -2
  34. package/dist/error/index.js +0 -3
  35. package/dist/utils/terminate.d.ts +0 -6
@@ -1,74 +1,68 @@
1
- import { EventEmitter } from 'node:events';
2
- import { BaseAgentWorker } from "./mode/base/agent.js";
3
- import { BaseAppWorker } from "./mode/base/app.js";
4
- // worker manager to record agent and worker forked by egg-cluster
5
- // can do some check stuff here to monitor the healthy
6
- export class WorkerManager extends EventEmitter {
7
- agent;
8
- workers = new Map();
9
- exception = 0;
10
- timer;
11
- constructor() {
12
- super();
13
- this.agent = null;
14
- }
15
- getWorkers() {
16
- return Array.from(this.workers.keys());
17
- }
18
- setAgent(agent) {
19
- this.agent = agent;
20
- }
21
- getAgent() {
22
- return this.agent;
23
- }
24
- deleteAgent() {
25
- this.agent = null;
26
- }
27
- setWorker(worker) {
28
- this.workers.set(worker.workerId, worker);
29
- }
30
- getWorker(workerId) {
31
- return this.workers.get(workerId);
32
- }
33
- deleteWorker(workerId) {
34
- this.workers.delete(workerId);
35
- }
36
- listWorkerIds() {
37
- return Array.from(this.workers.keys());
38
- }
39
- listWorkers() {
40
- return Array.from(this.workers.values());
41
- }
42
- getListeningWorkerIds() {
43
- const keys = [];
44
- for (const [id, worker] of this.workers.entries()) {
45
- if (worker.state === 'listening') {
46
- keys.push(id);
47
- }
48
- }
49
- return keys;
50
- }
51
- count() {
52
- return {
53
- agent: this.agent?.status === 'started' ? 1 : 0,
54
- worker: this.listWorkerIds().length,
55
- };
56
- }
57
- // check agent and worker must both alive
58
- // if exception appear 3 times, emit an exception event
59
- startCheck() {
60
- this.timer = setInterval(() => {
61
- const count = this.count();
62
- if (count.agent > 0 && count.worker > 0) {
63
- this.exception = 0;
64
- return;
65
- }
66
- this.exception++;
67
- if (this.exception >= 3) {
68
- this.emit('exception', count);
69
- clearInterval(this.timer);
70
- }
71
- }, 10000);
72
- }
73
- }
74
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ya2VyX21hbmFnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvd29ya2VyX21hbmFnZX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1REFBdUQ7SUFDdkQsVUFBVTtRQUNSLElBQUksQ0FBQyxLQUFLLEdBQUcsV0FBVyxDQUFDLEdBQUcsRUFBRTtZQUM1QixNQUFNLEtBQUssR0FBRyxJQUFJLENBQUMsS0FBSyxFQUFFLENBQUM7WUFDM0IsSUFBSSxLQUFLLENBQUMsS0FBSyxHQUFHLENBQUMsSUFBSSxLQUFLLENBQUMsTUFBTSxHQUFHLENBQUMsRUFBRSxDQUFDO2dCQUN4QyxJQUFJLENBQUMsU0FBUyxHQUFHLENBQUMsQ0FBQztnQkFDbkIsT0FBTztZQUNULENBQUM7WUFDRCxJQUFJLENBQUMsU0FBUyxFQUFFLENBQUM7WUFDakIsSUFBSSxJQUFJLENBQUMsU0FBUyxJQUFJLENBQUMsRUFBRSxDQUFDO2dCQUN4QixJQUFJLENBQUMsSUFBSSxDQUFDLFdBQVcsRUFBRSxLQUFLLENBQUMsQ0FBQztnQkFDOUIsYUFBYSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQztZQUM1QixDQUFDO1FBQ0gsQ0FBQyxFQUFFLEtBQUssQ0FBQyxDQUFDO0lBQ1osQ0FBQztDQUNGIn0=
1
+ import { EventEmitter } from "node:events";
2
+
3
+ //#region src/utils/worker_manager.ts
4
+ var WorkerManager = class extends EventEmitter {
5
+ agent;
6
+ workers = /* @__PURE__ */ new Map();
7
+ exception = 0;
8
+ timer;
9
+ constructor() {
10
+ super();
11
+ this.agent = null;
12
+ }
13
+ getWorkers() {
14
+ return Array.from(this.workers.keys());
15
+ }
16
+ setAgent(agent) {
17
+ this.agent = agent;
18
+ }
19
+ getAgent() {
20
+ return this.agent;
21
+ }
22
+ deleteAgent() {
23
+ this.agent = null;
24
+ }
25
+ setWorker(worker) {
26
+ this.workers.set(worker.workerId, worker);
27
+ }
28
+ getWorker(workerId) {
29
+ return this.workers.get(workerId);
30
+ }
31
+ deleteWorker(workerId) {
32
+ this.workers.delete(workerId);
33
+ }
34
+ listWorkerIds() {
35
+ return Array.from(this.workers.keys());
36
+ }
37
+ listWorkers() {
38
+ return Array.from(this.workers.values());
39
+ }
40
+ getListeningWorkerIds() {
41
+ const keys = [];
42
+ for (const [id, worker] of this.workers.entries()) if (worker.state === "listening") keys.push(id);
43
+ return keys;
44
+ }
45
+ count() {
46
+ return {
47
+ agent: this.agent?.status === "started" ? 1 : 0,
48
+ worker: this.listWorkerIds().length
49
+ };
50
+ }
51
+ startCheck() {
52
+ this.timer = setInterval(() => {
53
+ const count = this.count();
54
+ if (count.agent > 0 && count.worker > 0) {
55
+ this.exception = 0;
56
+ return;
57
+ }
58
+ this.exception++;
59
+ if (this.exception >= 3) {
60
+ this.emit("exception", count);
61
+ clearInterval(this.timer);
62
+ }
63
+ }, 1e4);
64
+ }
65
+ };
66
+
67
+ //#endregion
68
+ export { WorkerManager };
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
1
  {
2
2
  "name": "@eggjs/cluster",
3
- "version": "4.0.0-beta.34",
4
- "publishConfig": {
5
- "access": "public"
3
+ "version": "4.0.0-beta.36",
4
+ "description": "cluster manager for egg",
5
+ "keywords": [
6
+ "cluster",
7
+ "egg",
8
+ "process"
9
+ ],
10
+ "homepage": "https://github.com/eggjs/egg/tree/next/packages/cluster",
11
+ "bugs": {
12
+ "url": "https://github.com/eggjs/egg/issues"
6
13
  },
14
+ "license": "MIT",
15
+ "author": "dead-horse <dead_horse@qq.com>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/eggjs/egg.git",
19
+ "directory": "packages/cluster"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
7
24
  "type": "module",
25
+ "main": "./dist/index.js",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
8
28
  "exports": {
9
29
  ".": "./dist/index.js",
10
30
  "./agent_worker": "./dist/agent_worker.js",
11
31
  "./app_worker": "./dist/app_worker.js",
12
32
  "./package.json": "./package.json"
13
33
  },
14
- "main": "./dist/index.js",
15
- "module": "./dist/index.js",
16
- "types": "./dist/index.d.ts",
17
- "description": "cluster manager for egg",
18
- "files": [
19
- "dist"
20
- ],
21
- "repository": {
22
- "type": "git",
23
- "url": "git://github.com/eggjs/egg.git",
24
- "directory": "packages/cluster"
25
- },
26
- "keywords": [
27
- "egg",
28
- "cluster",
29
- "process"
30
- ],
31
- "author": "dead-horse <dead_horse@qq.com>",
32
- "license": "MIT",
33
- "bugs": {
34
- "url": "https://github.com/eggjs/egg/issues"
34
+ "publishConfig": {
35
+ "access": "public"
35
36
  },
36
- "homepage": "https://github.com/eggjs/egg/tree/next/packages/cluster",
37
37
  "dependencies": {
38
38
  "@fengmk2/ps-tree": "^2.0.1",
39
39
  "cfork": "^2.0.0",
@@ -45,27 +45,26 @@
45
45
  "sendmessage": "^3.0.1",
46
46
  "terminal-link": "^5.0.0",
47
47
  "utility": "^2.5.0",
48
- "@eggjs/utils": "5.0.0-beta.34"
48
+ "@eggjs/utils": "5.0.0-beta.36"
49
49
  },
50
50
  "devDependencies": {
51
51
  "address": "2",
52
52
  "coffee": "5",
53
- "tsdown": "0.15.11",
53
+ "tsdown": "^0.18.2",
54
54
  "typescript": "^5.9.3",
55
55
  "urllib": "^4.8.2",
56
- "vitest": "4.0.5",
57
- "@eggjs/mock": "7.0.0-beta.34",
58
- "@eggjs/errors": "3.0.0-beta.34",
59
- "@eggjs/supertest": "9.0.0-beta.34",
60
- "@eggjs/tsconfig": "3.1.0-beta.34"
56
+ "vitest": "^4.0.15",
57
+ "@eggjs/mock": "7.0.0-beta.36",
58
+ "@eggjs/errors": "3.0.0-beta.36",
59
+ "@eggjs/supertest": "9.0.0-beta.36",
60
+ "@eggjs/tsconfig": "3.1.0-beta.36"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">=22.18.0"
64
64
  },
65
65
  "scripts": {
66
- "build": "tsdown && rimraf dist *.tsbuildinfo && tsc -p tsconfig.build.json",
67
66
  "lint": "oxlint",
68
- "typecheck": "tsc --noEmit",
67
+ "typecheck": "tsgo --noEmit",
69
68
  "test": "vitest run"
70
69
  }
71
70
  }
@@ -1,2 +0,0 @@
1
- export * from './ClusterAgentWorkerError.ts';
2
- export * from './ClusterWorkerExceptionError.ts';
@@ -1,3 +0,0 @@
1
- export * from "./ClusterAgentWorkerError.js";
2
- export * from "./ClusterWorkerExceptionError.js";
3
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZXJyb3IvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyw4QkFBOEIsQ0FBQztBQUM3QyxjQUFjLGtDQUFrQyxDQUFDIn0=
@@ -1,6 +0,0 @@
1
- import { ChildProcess } from 'node:child_process';
2
- interface SubProcess extends ChildProcess {
3
- process?: ChildProcess;
4
- }
5
- export declare function terminate(subProcess: SubProcess, timeout: number): Promise<void>;
6
- export {};