@eggjs/cluster 3.0.1 → 3.1.0-beta.11

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 (127) hide show
  1. package/README.md +17 -21
  2. package/dist/agent_worker.d.ts +1 -0
  3. package/dist/agent_worker.js +55 -0
  4. package/dist/app_worker.d.ts +1 -0
  5. package/dist/app_worker.js +131 -0
  6. package/dist/dirname.js +11 -0
  7. package/dist/error/ClusterAgentWorkerError.d.ts +13 -0
  8. package/dist/error/ClusterAgentWorkerError.js +22 -0
  9. package/dist/error/ClusterWorkerExceptionError.d.ts +10 -0
  10. package/dist/error/ClusterWorkerExceptionError.js +17 -0
  11. package/dist/index.d.ts +22 -0
  12. package/dist/index.js +24 -0
  13. package/dist/master.d.ts +96 -0
  14. package/dist/master.js +426 -0
  15. package/dist/utils/messenger.d.ts +96 -0
  16. package/dist/utils/messenger.js +144 -0
  17. package/dist/utils/mode/base/agent.d.ts +45 -0
  18. package/dist/utils/mode/base/agent.js +63 -0
  19. package/dist/utils/mode/base/app.d.ts +56 -0
  20. package/dist/utils/mode/base/app.js +77 -0
  21. package/dist/utils/mode/impl/process/agent.d.ts +22 -0
  22. package/dist/utils/mode/impl/process/agent.js +93 -0
  23. package/dist/utils/mode/impl/process/app.d.ts +12 -0
  24. package/dist/utils/mode/impl/process/app.js +117 -0
  25. package/dist/utils/mode/impl/worker_threads/agent.d.ts +22 -0
  26. package/dist/utils/mode/impl/worker_threads/agent.js +79 -0
  27. package/dist/utils/mode/impl/worker_threads/app.d.ts +13 -0
  28. package/dist/utils/mode/impl/worker_threads/app.js +128 -0
  29. package/dist/utils/options.d.ts +83 -0
  30. package/dist/utils/options.js +56 -0
  31. package/dist/utils/terminate.js +62 -0
  32. package/dist/utils/worker_manager.d.ts +32 -0
  33. package/dist/utils/worker_manager.js +68 -0
  34. package/package.json +41 -63
  35. package/dist/commonjs/agent_worker.d.ts +0 -1
  36. package/dist/commonjs/agent_worker.js +0 -69
  37. package/dist/commonjs/app_worker.d.ts +0 -1
  38. package/dist/commonjs/app_worker.js +0 -173
  39. package/dist/commonjs/dirname.d.ts +0 -1
  40. package/dist/commonjs/dirname.js +0 -17
  41. package/dist/commonjs/error/ClusterAgentWorkerError.d.ts +0 -10
  42. package/dist/commonjs/error/ClusterAgentWorkerError.js +0 -23
  43. package/dist/commonjs/error/ClusterWorkerExceptionError.d.ts +0 -7
  44. package/dist/commonjs/error/ClusterWorkerExceptionError.js +0 -18
  45. package/dist/commonjs/error/index.d.ts +0 -2
  46. package/dist/commonjs/error/index.js +0 -19
  47. package/dist/commonjs/index.d.ts +0 -17
  48. package/dist/commonjs/index.js +0 -37
  49. package/dist/commonjs/master.d.ts +0 -90
  50. package/dist/commonjs/master.js +0 -560
  51. package/dist/commonjs/package.json +0 -3
  52. package/dist/commonjs/utils/messenger.d.ts +0 -92
  53. package/dist/commonjs/utils/messenger.js +0 -186
  54. package/dist/commonjs/utils/mode/base/agent.d.ts +0 -38
  55. package/dist/commonjs/utils/mode/base/agent.js +0 -68
  56. package/dist/commonjs/utils/mode/base/app.d.ts +0 -48
  57. package/dist/commonjs/utils/mode/base/app.js +0 -83
  58. package/dist/commonjs/utils/mode/impl/process/agent.d.ts +0 -18
  59. package/dist/commonjs/utils/mode/impl/process/agent.js +0 -108
  60. package/dist/commonjs/utils/mode/impl/process/app.d.ts +0 -21
  61. package/dist/commonjs/utils/mode/impl/process/app.js +0 -127
  62. package/dist/commonjs/utils/mode/impl/worker_threads/agent.d.ts +0 -18
  63. package/dist/commonjs/utils/mode/impl/worker_threads/agent.js +0 -91
  64. package/dist/commonjs/utils/mode/impl/worker_threads/app.d.ts +0 -26
  65. package/dist/commonjs/utils/mode/impl/worker_threads/app.js +0 -142
  66. package/dist/commonjs/utils/options.d.ts +0 -80
  67. package/dist/commonjs/utils/options.js +0 -83
  68. package/dist/commonjs/utils/terminate.d.ts +0 -6
  69. package/dist/commonjs/utils/terminate.js +0 -89
  70. package/dist/commonjs/utils/worker_manager.d.ts +0 -25
  71. package/dist/commonjs/utils/worker_manager.js +0 -76
  72. package/dist/esm/agent_worker.d.ts +0 -1
  73. package/dist/esm/agent_worker.js +0 -67
  74. package/dist/esm/app_worker.d.ts +0 -1
  75. package/dist/esm/app_worker.js +0 -168
  76. package/dist/esm/dirname.d.ts +0 -1
  77. package/dist/esm/dirname.js +0 -11
  78. package/dist/esm/error/ClusterAgentWorkerError.d.ts +0 -10
  79. package/dist/esm/error/ClusterAgentWorkerError.js +0 -19
  80. package/dist/esm/error/ClusterWorkerExceptionError.d.ts +0 -7
  81. package/dist/esm/error/ClusterWorkerExceptionError.js +0 -14
  82. package/dist/esm/error/index.d.ts +0 -2
  83. package/dist/esm/error/index.js +0 -3
  84. package/dist/esm/index.d.ts +0 -17
  85. package/dist/esm/index.js +0 -19
  86. package/dist/esm/master.d.ts +0 -90
  87. package/dist/esm/master.js +0 -553
  88. package/dist/esm/package.json +0 -3
  89. package/dist/esm/utils/messenger.d.ts +0 -92
  90. package/dist/esm/utils/messenger.js +0 -179
  91. package/dist/esm/utils/mode/base/agent.d.ts +0 -38
  92. package/dist/esm/utils/mode/base/agent.js +0 -60
  93. package/dist/esm/utils/mode/base/app.d.ts +0 -48
  94. package/dist/esm/utils/mode/base/app.js +0 -75
  95. package/dist/esm/utils/mode/impl/process/agent.d.ts +0 -18
  96. package/dist/esm/utils/mode/impl/process/agent.js +0 -103
  97. package/dist/esm/utils/mode/impl/process/app.d.ts +0 -21
  98. package/dist/esm/utils/mode/impl/process/app.js +0 -119
  99. package/dist/esm/utils/mode/impl/worker_threads/agent.d.ts +0 -18
  100. package/dist/esm/utils/mode/impl/worker_threads/agent.js +0 -83
  101. package/dist/esm/utils/mode/impl/worker_threads/app.d.ts +0 -26
  102. package/dist/esm/utils/mode/impl/worker_threads/app.js +0 -137
  103. package/dist/esm/utils/options.d.ts +0 -80
  104. package/dist/esm/utils/options.js +0 -77
  105. package/dist/esm/utils/terminate.d.ts +0 -6
  106. package/dist/esm/utils/terminate.js +0 -86
  107. package/dist/esm/utils/worker_manager.d.ts +0 -25
  108. package/dist/esm/utils/worker_manager.js +0 -72
  109. package/dist/package.json +0 -4
  110. package/src/agent_worker.ts +0 -80
  111. package/src/app_worker.ts +0 -196
  112. package/src/dirname.ts +0 -11
  113. package/src/error/ClusterAgentWorkerError.ts +0 -19
  114. package/src/error/ClusterWorkerExceptionError.ts +0 -17
  115. package/src/error/index.ts +0 -2
  116. package/src/index.ts +0 -26
  117. package/src/master.ts +0 -658
  118. package/src/utils/messenger.ts +0 -207
  119. package/src/utils/mode/base/agent.ts +0 -90
  120. package/src/utils/mode/base/app.ts +0 -119
  121. package/src/utils/mode/impl/process/agent.ts +0 -119
  122. package/src/utils/mode/impl/process/app.ts +0 -140
  123. package/src/utils/mode/impl/worker_threads/agent.ts +0 -99
  124. package/src/utils/mode/impl/worker_threads/app.ts +0 -164
  125. package/src/utils/options.ts +0 -171
  126. package/src/utils/terminate.ts +0 -97
  127. package/src/utils/worker_manager.ts +0 -87
@@ -0,0 +1,83 @@
1
+ import { SecureContextOptions } from "node:tls";
2
+
3
+ //#region src/utils/options.d.ts
4
+ interface ClusterHTTPSSecureOptions {
5
+ key: SecureContextOptions['key'];
6
+ cert: SecureContextOptions['cert'];
7
+ ca?: SecureContextOptions['ca'];
8
+ passphrase?: SecureContextOptions['passphrase'];
9
+ }
10
+ type ClusterStartMode = 'process' | 'worker_threads';
11
+ /** Cluster start options */
12
+ interface ClusterOptions {
13
+ /**
14
+ * specify framework that can be absolute path or npm package
15
+ */
16
+ framework?: string;
17
+ /**
18
+ * @deprecated please use framework instead
19
+ */
20
+ customEgg?: string;
21
+ /** directory of application, default to `process.cwd()` */
22
+ baseDir?: string;
23
+ /**
24
+ * numbers of app workers, default to `os.cpus().length`
25
+ */
26
+ workers?: number | string;
27
+ /**
28
+ * listening port, default to `7001`(http) or `8443`(https)
29
+ */
30
+ port?: number | string | null;
31
+ /**
32
+ * listening a debug port on http protocol
33
+ */
34
+ debugPort?: number;
35
+ /**
36
+ * https options, { key, cert, ca }, full path
37
+ */
38
+ https?: ClusterHTTPSSecureOptions | boolean;
39
+ /**
40
+ * @deprecated please use `options.https.key` instead
41
+ */
42
+ key?: ClusterHTTPSSecureOptions['key'];
43
+ /**
44
+ * @deprecated please use `options.https.cert` instead
45
+ */
46
+ cert?: ClusterHTTPSSecureOptions['cert'];
47
+ /**
48
+ * will inject into worker/agent process
49
+ */
50
+ require?: string | string[];
51
+ /**
52
+ * will save master pid to this file
53
+ */
54
+ pidFile?: string;
55
+ /**
56
+ * custom env, default is `process.env.EGG_SERVER_ENV`
57
+ */
58
+ env?: string;
59
+ /**
60
+ * default is `'process'`, use `'worker_threads'` to start the app & agent worker by worker_threads
61
+ */
62
+ startMode?: ClusterStartMode;
63
+ /**
64
+ * startup port of each app worker, such as: `[7001, 7002, 7003]`, only effects when the startMode is `'worker_threads'`
65
+ */
66
+ ports?: number[];
67
+ /**
68
+ * sticky mode server
69
+ */
70
+ sticky?: boolean;
71
+ /** customized plugins, for unittest */
72
+ plugins?: object;
73
+ isDebug?: boolean;
74
+ }
75
+ interface ParsedClusterOptions extends ClusterOptions {
76
+ port?: number;
77
+ baseDir: string;
78
+ workers: number;
79
+ framework: string;
80
+ startMode: ClusterStartMode;
81
+ }
82
+ //#endregion
83
+ export { ClusterHTTPSSecureOptions, ClusterOptions, ClusterStartMode, ParsedClusterOptions };
@@ -0,0 +1,56 @@
1
+ import os from "node:os";
2
+ import { debuglog } from "node:util";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ import assert from "node:assert";
6
+ import { getFrameworkPath, importModule } from "@eggjs/utils";
7
+
8
+ //#region src/utils/options.ts
9
+ const debug = debuglog("egg/cluster/utils/options");
10
+ async function parseOptions(options) {
11
+ options = {
12
+ baseDir: process.cwd(),
13
+ port: options?.https ? 8443 : void 0,
14
+ startMode: "process",
15
+ env: process.env.EGG_SERVER_ENV,
16
+ ...options
17
+ };
18
+ const pkgPath = path.join(options.baseDir, "package.json");
19
+ assert(fs.existsSync(pkgPath), `${pkgPath} should exist`);
20
+ options.framework = getFrameworkPath({
21
+ baseDir: options.baseDir,
22
+ framework: options.framework ?? options.customEgg
23
+ });
24
+ debug("[parseOptions] %o", options);
25
+ const egg = await importModule(options.framework, { paths: [options.baseDir] });
26
+ assert(egg.Application, `should define Application in ${options.framework}`);
27
+ assert(egg.Agent, `should define Agent in ${options.framework}`);
28
+ if (options.https === true) {
29
+ console.warn("[@eggjs/cluster:deprecated] [master] Please use `https: { key, cert, ca }` instead of `https: true`");
30
+ options.https = {
31
+ key: options.key,
32
+ cert: options.cert
33
+ };
34
+ }
35
+ if (options.https) {
36
+ assert(options.https.key, "options.https.key should exists");
37
+ if (typeof options.https.key === "string") assert(fs.existsSync(options.https.key), "options.https.key file should exists");
38
+ assert(options.https.cert, "options.https.cert should exists");
39
+ if (typeof options.https.cert === "string") assert(fs.existsSync(options.https.cert), "options.https.cert file should exists");
40
+ if (typeof options.https.ca === "string") assert(fs.existsSync(options.https.ca), "options.https.ca file should exists");
41
+ }
42
+ if (options.port && typeof options.port === "string") options.port = parseInt(options.port);
43
+ if (options.port === null) options.port = void 0;
44
+ if (options.workers && typeof options.workers === "string") options.workers = parseInt(options.workers);
45
+ if (!options.workers) options.workers = os.cpus().length;
46
+ if (options.require) {
47
+ if (typeof options.require === "string") options.require = [options.require];
48
+ }
49
+ if (process.env.NODE_ENV === "production") process.env.NO_DEPRECATION = "*";
50
+ const isDebug = process.execArgv.some((argv) => argv.includes("--debug") || argv.includes("--inspect"));
51
+ if (isDebug) options.isDebug = isDebug;
52
+ return options;
53
+ }
54
+
55
+ //#endregion
56
+ export { parseOptions };
@@ -0,0 +1,62 @@
1
+ import { debuglog } from "node:util";
2
+ import { once } from "node:events";
3
+ import { ChildProcess } from "node:child_process";
4
+ import { setTimeout } from "node:timers/promises";
5
+ import { pstree } from "@fengmk2/ps-tree";
6
+
7
+ //#region src/utils/terminate.ts
8
+ const debug = debuglog("egg/cluster/utils/terminate");
9
+ async function terminate(subProcess, timeout) {
10
+ const pid = subProcess.process?.pid ?? subProcess.pid;
11
+ const childPids = await getChildPids(pid);
12
+ await Promise.all([killProcess(subProcess, timeout), killChildren(childPids, timeout)]);
13
+ }
14
+ async function killProcess(subProcess, timeout) {
15
+ (subProcess.process ?? subProcess).kill("SIGTERM");
16
+ await Promise.race([once(subProcess, "exit"), setTimeout(timeout)]);
17
+ if (subProcess.killed) return;
18
+ (subProcess.process ?? subProcess).kill("SIGKILL");
19
+ }
20
+ async function killChildren(childrenPids, timeout) {
21
+ if (childrenPids.length === 0) return;
22
+ kill(childrenPids, "SIGTERM");
23
+ const start = Date.now();
24
+ const checkInterval = 400;
25
+ let unterminated = [];
26
+ while (Date.now() - start < timeout - checkInterval) {
27
+ await setTimeout(checkInterval);
28
+ unterminated = getUnterminatedProcesses(childrenPids);
29
+ if (unterminated.length === 0) return;
30
+ }
31
+ kill(unterminated, "SIGKILL");
32
+ }
33
+ async function getChildPids(pid) {
34
+ let childrenPids = [];
35
+ try {
36
+ childrenPids = (await pstree(pid)).map((c) => parseInt(c.PID));
37
+ } catch (err) {
38
+ debug("pstree %s error: %s, ignore it", pid, err);
39
+ }
40
+ return childrenPids;
41
+ }
42
+ function kill(pids, signal) {
43
+ for (const pid of pids) try {
44
+ process.kill(pid, signal);
45
+ } catch (err) {
46
+ debug("kill %s error: %s, signal: %s, ignore it", pid, err, signal);
47
+ }
48
+ }
49
+ function getUnterminatedProcesses(pids) {
50
+ return pids.filter((pid) => {
51
+ try {
52
+ process.kill(pid, 0);
53
+ return true;
54
+ } catch (err) {
55
+ debug("kill %s error: %s, it still alive", pid, err);
56
+ return false;
57
+ }
58
+ });
59
+ }
60
+
61
+ //#endregion
62
+ export { terminate };
@@ -0,0 +1,32 @@
1
+ import { BaseAgentWorker } from "./mode/base/agent.js";
2
+ import { BaseAppWorker } from "./mode/base/app.js";
3
+ import { EventEmitter } from "node:events";
4
+ import * as worker_threads0 from "worker_threads";
5
+ import * as cluster0 from "cluster";
6
+ import * as child_process0 from "child_process";
7
+
8
+ //#region src/utils/worker_manager.d.ts
9
+ declare class WorkerManager extends EventEmitter {
10
+ agent: BaseAgentWorker | null;
11
+ workers: Map<number, BaseAppWorker<worker_threads0.Worker | cluster0.Worker>>;
12
+ exception: number;
13
+ timer: NodeJS.Timeout;
14
+ constructor();
15
+ getWorkers(): number[];
16
+ setAgent(agent: BaseAgentWorker): void;
17
+ getAgent(): BaseAgentWorker<worker_threads0.Worker | child_process0.ChildProcess> | null;
18
+ deleteAgent(): void;
19
+ setWorker(worker: BaseAppWorker): void;
20
+ getWorker(workerId: number): BaseAppWorker<worker_threads0.Worker | cluster0.Worker> | undefined;
21
+ deleteWorker(workerId: number): void;
22
+ listWorkerIds(): number[];
23
+ listWorkers(): BaseAppWorker<worker_threads0.Worker | cluster0.Worker>[];
24
+ getListeningWorkerIds(): number[];
25
+ count(): {
26
+ agent: number;
27
+ worker: number;
28
+ };
29
+ startCheck(): void;
30
+ }
31
+ //#endregion
32
+ export { WorkerManager };
@@ -0,0 +1,68 @@
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,25 +1,27 @@
1
1
  {
2
2
  "name": "@eggjs/cluster",
3
- "version": "3.0.1",
3
+ "version": "3.1.0-beta.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "description": "cluster manager for egg",
8
- "scripts": {
9
- "lint": "eslint --cache src test --ext .ts",
10
- "pretest": "npm run lint -- --fix && npm run prepublishOnly",
11
- "test": "egg-bin test",
12
- "preci": "npm run lint && npm run prepublishOnly",
13
- "ci": "egg-bin test",
14
- "prepublishOnly": "tshy && tshy-after && attw --pack"
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./dist/index.js",
10
+ "./agent_worker": "./dist/agent_worker.js",
11
+ "./app_worker": "./dist/app_worker.js",
12
+ "./package.json": "./package.json"
15
13
  },
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "description": "cluster manager for egg",
16
18
  "files": [
17
- "dist",
18
- "src"
19
+ "dist"
19
20
  ],
20
21
  "repository": {
21
22
  "type": "git",
22
- "url": "git+https://github.com/eggjs/cluster.git"
23
+ "url": "git://github.com/eggjs/egg.git",
24
+ "directory": "packages/cluster"
23
25
  },
24
26
  "keywords": [
25
27
  "egg",
@@ -29,66 +31,42 @@
29
31
  "author": "dead-horse <dead_horse@qq.com>",
30
32
  "license": "MIT",
31
33
  "bugs": {
32
- "url": "https://github.com/eggjs/cluster/issues"
34
+ "url": "https://github.com/eggjs/egg/issues"
33
35
  },
34
- "homepage": "https://github.com/eggjs/cluster#readme",
36
+ "homepage": "https://github.com/eggjs/egg/tree/next/packages/cluster",
35
37
  "dependencies": {
36
- "@eggjs/utils": "^4.2.1",
37
38
  "@fengmk2/ps-tree": "^2.0.1",
38
39
  "cfork": "^2.0.0",
39
40
  "cluster-reload": "^2.0.0",
40
- "detect-port": "^2.0.1",
41
- "egg-logger": "^3.6.0",
42
- "get-ready": "^3.2.0",
41
+ "detect-port": "^2.1.0",
42
+ "egg-logger": "^3.5.0",
43
+ "get-ready": "^3.1.0",
43
44
  "graceful-process": "^2.0.0",
44
45
  "sendmessage": "^3.0.1",
45
- "terminal-link": "^2.1.1",
46
- "utility": "^2.2.0"
46
+ "terminal-link": "^5.0.0",
47
+ "utility": "^2.5.0",
48
+ "@eggjs/utils": "4.5.0-beta.11"
47
49
  },
48
50
  "devDependencies": {
49
- "@arethetypeswrong/cli": "^0.17.1",
50
- "@eggjs/bin": "^7.0.0",
51
- "@eggjs/mock": "beta",
52
- "@eggjs/supertest": "^8.1.1",
53
- "@eggjs/tsconfig": "1",
54
- "@types/mocha": "10",
55
- "@types/node": "22",
56
- "address": "^2.0.3",
57
- "coffee": "^5.5.1",
58
- "egg": "beta",
59
- "egg-errors": "^2.2.0",
60
- "eslint": "8",
61
- "eslint-config-egg": "14",
62
- "ts-node": "^10.9.1",
63
- "tshy": "3",
64
- "tshy-after": "1",
65
- "typescript": "5",
66
- "urllib": "^4.6.8"
51
+ "@types/node": "24.5.2",
52
+ "address": "2",
53
+ "coffee": "5",
54
+ "egg-errors": "^2.3.2",
55
+ "tsdown": "^0.15.4",
56
+ "typescript": "5.9.2",
57
+ "urllib": "^4.6.11",
58
+ "vitest": "4.0.0-beta.13",
59
+ "@eggjs/tsconfig": "3.1.0-beta.11",
60
+ "@eggjs/supertest": "8.3.0-beta.11",
61
+ "@eggjs/mock": "6.1.0-beta.11"
67
62
  },
68
63
  "engines": {
69
- "node": ">= 18.19.0"
64
+ "node": ">= 20.19.0"
70
65
  },
71
- "type": "module",
72
- "tshy": {
73
- "exports": {
74
- ".": "./src/index.ts",
75
- "./package.json": "./package.json"
76
- }
77
- },
78
- "exports": {
79
- ".": {
80
- "import": {
81
- "types": "./dist/esm/index.d.ts",
82
- "default": "./dist/esm/index.js"
83
- },
84
- "require": {
85
- "types": "./dist/commonjs/index.d.ts",
86
- "default": "./dist/commonjs/index.js"
87
- }
88
- },
89
- "./package.json": "./package.json"
90
- },
91
- "types": "./dist/commonjs/index.d.ts",
92
- "main": "./dist/commonjs/index.js",
93
- "module": "./dist/esm/index.js"
94
- }
66
+ "scripts": {
67
+ "build": "tsdown",
68
+ "lint": "oxlint",
69
+ "typecheck": "tsc --noEmit",
70
+ "test": "vitest run"
71
+ }
72
+ }
@@ -1 +0,0 @@
1
- export {};
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_util_1 = require("node:util");
4
- const egg_logger_1 = require("egg-logger");
5
- const utils_1 = require("@eggjs/utils");
6
- const agent_js_1 = require("./utils/mode/impl/worker_threads/agent.js");
7
- const agent_js_2 = require("./utils/mode/impl/process/agent.js");
8
- const debug = (0, node_util_1.debuglog)('@eggjs/cluster/agent_worker');
9
- /**
10
- * agent worker is child_process forked by master.
11
- *
12
- * agent worker only exit in two cases:
13
- * - receive signal SIGTERM, exit code 0 (exit gracefully)
14
- * - receive disconnect event, exit code 110 (maybe master exit in accident)
15
- */
16
- async function main() {
17
- // $ node agent_worker.js options
18
- const options = JSON.parse(process.argv[2]);
19
- if (options.require) {
20
- // inject
21
- for (const mod of options.require) {
22
- await (0, utils_1.importModule)(mod, {
23
- paths: [options.baseDir],
24
- });
25
- }
26
- }
27
- let AgentWorker;
28
- if (options.startMode === 'worker_threads') {
29
- AgentWorker = agent_js_1.AgentThreadWorker;
30
- }
31
- else {
32
- AgentWorker = agent_js_2.AgentProcessWorker;
33
- }
34
- const consoleLogger = new egg_logger_1.EggConsoleLogger({ level: process.env.EGG_AGENT_WORKER_LOGGER_LEVEL });
35
- const { Agent } = await (0, utils_1.importModule)(options.framework, {
36
- paths: [options.baseDir],
37
- });
38
- debug('new Agent with options %j', options);
39
- let agent;
40
- try {
41
- agent = new Agent(options);
42
- }
43
- catch (err) {
44
- consoleLogger.error(err);
45
- throw err;
46
- }
47
- function startErrorHandler(err) {
48
- consoleLogger.error(err);
49
- consoleLogger.error('[agent_worker] start error, exiting with code:1');
50
- AgentWorker.kill();
51
- }
52
- agent.ready((err) => {
53
- // don't send started message to master when start error
54
- if (err) {
55
- return;
56
- }
57
- agent.removeListener('error', startErrorHandler);
58
- AgentWorker.send({ action: 'agent-start', to: 'master' });
59
- });
60
- // exit if agent start error
61
- agent.once('error', startErrorHandler);
62
- AgentWorker.gracefulExit({
63
- logger: consoleLogger,
64
- label: 'agent_worker',
65
- beforeExit: () => agent.close(),
66
- });
67
- }
68
- main();
69
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnRfd29ya2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FnZW50X3dvcmtlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHlDQUFxQztBQUNyQywyQ0FBK0Q7QUFDL0Qsd0NBQTRDO0FBRTVDLHdFQUE4RTtBQUM5RSxpRUFBd0U7QUFFeEUsTUFBTSxLQUFLLEdBQUcsSUFBQSxvQkFBUSxFQUFDLDZCQUE2QixDQUFDLENBQUM7QUFFdEQ7Ozs7OztHQU1HO0FBQ0gsS0FBSyxVQUFVLElBQUk7SUFDakIsaUNBQWlDO0lBQ2pDLE1BQU0sT0FBTyxHQUFHLElBQUksQ0FBQyxLQUF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