nmtjs 0.15.0-beta.13 → 0.15.0-beta.14
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/dist/entrypoints/main.js +79 -10
- package/dist/entrypoints/main.js.map +1 -1
- package/dist/entrypoints/thread.js +129 -27
- package/dist/entrypoints/thread.js.map +1 -1
- package/dist/runtime/server/applications.d.ts +4 -1
- package/dist/runtime/server/applications.js +38 -15
- package/dist/runtime/server/applications.js.map +1 -1
- package/dist/runtime/server/config.d.ts +4 -0
- package/dist/runtime/server/config.js.map +1 -1
- package/dist/runtime/server/pool.d.ts +4 -2
- package/dist/runtime/server/pool.js +91 -20
- package/dist/runtime/server/pool.js.map +1 -1
- package/dist/runtime/server/proxy.js +7 -1
- package/dist/runtime/server/proxy.js.map +1 -1
- package/dist/runtime/server/server.d.ts +17 -1
- package/dist/runtime/server/server.js.map +1 -1
- package/dist/runtime/types.d.ts +13 -3
- package/dist/vite/servers/worker.d.ts +5 -2
- package/dist/vite/servers/worker.js +27 -0
- package/dist/vite/servers/worker.js.map +1 -1
- package/package.json +12 -12
- package/src/entrypoints/main.ts +103 -15
- package/src/entrypoints/thread.ts +145 -34
- package/src/runtime/server/applications.ts +53 -14
- package/src/runtime/server/config.ts +4 -0
- package/src/runtime/server/pool.ts +100 -23
- package/src/runtime/server/proxy.ts +7 -1
- package/src/runtime/server/server.ts +23 -1
- package/src/runtime/types.ts +16 -1
- package/src/vite/servers/worker.ts +37 -1
package/dist/entrypoints/main.js
CHANGED
|
@@ -21,10 +21,12 @@ const applicationsConfig = __APPLICATIONS_CONFIG__ ? JSON.parse(__APPLICATIONS_C
|
|
|
21
21
|
let _viteServerEvents;
|
|
22
22
|
let _viteWorkerServer;
|
|
23
23
|
let server;
|
|
24
|
+
let hasActiveWorkerError = false;
|
|
25
|
+
const isDev = _vite?.mode === 'development';
|
|
24
26
|
if (import.meta.env.DEV && import.meta.hot) {
|
|
25
27
|
import.meta.hot.accept('#server', async (module) => {
|
|
26
|
-
await
|
|
27
|
-
await
|
|
28
|
+
await shutdownServer();
|
|
29
|
+
await bootWithHandling(module?.default);
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
if (_vite) {
|
|
@@ -33,12 +35,14 @@ if (_vite) {
|
|
|
33
35
|
/* @vite-ignore */
|
|
34
36
|
_vite.options.configPath)).then((m) => m.default);
|
|
35
37
|
_viteServerEvents = new EventEmitter();
|
|
38
|
+
_viteServerEvents.on('worker-error', handleWorkerError);
|
|
39
|
+
_viteServerEvents.on('worker-ready', handleWorkerReady);
|
|
36
40
|
_viteWorkerServer = await createWorkerServer(_vite.options, _vite.mode, neemataConfig, _viteServerEvents);
|
|
37
41
|
}
|
|
38
|
-
async function
|
|
39
|
-
if (!isServerConfig(
|
|
42
|
+
async function bootServer(configValue) {
|
|
43
|
+
if (!isServerConfig(configValue))
|
|
40
44
|
throw new InvalidServerConfigError();
|
|
41
|
-
|
|
45
|
+
const workerConfig = {
|
|
42
46
|
path: fileURLToPath(import.meta.resolve(`./thread${_ext}`)),
|
|
43
47
|
workerData: { vite: _vite?.mode },
|
|
44
48
|
worker: _viteServerEvents
|
|
@@ -46,28 +50,92 @@ async function createServer(config) {
|
|
|
46
50
|
_viteServerEvents.emit('worker', worker);
|
|
47
51
|
}
|
|
48
52
|
: undefined,
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
events: _viteServerEvents,
|
|
54
|
+
};
|
|
55
|
+
const appServer = new ApplicationServer(configValue, applicationsConfig, workerConfig);
|
|
56
|
+
try {
|
|
57
|
+
await appServer.start();
|
|
58
|
+
server = appServer;
|
|
59
|
+
clearWorkerErrorOverlay();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
await appServer.stop().catch(() => { });
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function bootWithHandling(configValue) {
|
|
67
|
+
try {
|
|
68
|
+
await bootServer(configValue);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
handleStartupError(error);
|
|
72
|
+
if (!isDev)
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
51
75
|
}
|
|
52
76
|
let isTerminating = false;
|
|
53
77
|
async function handleTermination() {
|
|
54
78
|
if (isTerminating)
|
|
55
79
|
return;
|
|
56
80
|
isTerminating = true;
|
|
57
|
-
await
|
|
81
|
+
await shutdownServer();
|
|
58
82
|
_viteWorkerServer?.close();
|
|
59
83
|
process.exit(0);
|
|
60
84
|
}
|
|
61
85
|
function handleUnexpectedError(error) {
|
|
62
86
|
console.error(new Error('Unexpected Error:', { cause: error }));
|
|
63
87
|
}
|
|
88
|
+
async function shutdownServer() {
|
|
89
|
+
if (!server)
|
|
90
|
+
return;
|
|
91
|
+
try {
|
|
92
|
+
await server.stop();
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error(new Error('Failed to stop application server', { cause: error }));
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
server = undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function handleWorkerError(event) {
|
|
102
|
+
hasActiveWorkerError = true;
|
|
103
|
+
console.error(new Error(`Worker ${event.application} thread ${event.threadId} error`, {
|
|
104
|
+
cause: event.error,
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
function handleWorkerReady(_) {
|
|
108
|
+
clearWorkerErrorOverlay();
|
|
109
|
+
}
|
|
110
|
+
function handleStartupError(error) {
|
|
111
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
112
|
+
if (_viteServerEvents) {
|
|
113
|
+
_viteServerEvents.emit('worker-error', {
|
|
114
|
+
application: 'server',
|
|
115
|
+
threadId: -1,
|
|
116
|
+
error: normalized,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
hasActiveWorkerError = true;
|
|
121
|
+
console.error(new Error('Failed to start application server', { cause: normalized }));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function clearWorkerErrorOverlay() {
|
|
125
|
+
if (!hasActiveWorkerError)
|
|
126
|
+
return;
|
|
127
|
+
hasActiveWorkerError = false;
|
|
128
|
+
}
|
|
64
129
|
process.once('SIGTERM', handleTermination);
|
|
65
130
|
process.once('SIGINT', handleTermination);
|
|
66
131
|
process.on('uncaughtException', handleUnexpectedError);
|
|
67
132
|
process.on('unhandledRejection', handleUnexpectedError);
|
|
68
|
-
await
|
|
133
|
+
await bootWithHandling(await import(
|
|
69
134
|
// @ts-expect-error
|
|
70
|
-
'#server').then((m) => m.default))
|
|
135
|
+
'#server').then((m) => m.default)).catch(() => {
|
|
136
|
+
if (!isDev)
|
|
137
|
+
process.exit(1);
|
|
138
|
+
});
|
|
71
139
|
const { format } = Intl.NumberFormat('en', {
|
|
72
140
|
notation: 'compact',
|
|
73
141
|
maximumFractionDigits: 2,
|
|
@@ -79,6 +147,7 @@ const printMem = () => {
|
|
|
79
147
|
const memoryUsage = process.memoryUsage();
|
|
80
148
|
console.log(`Memory Usage: RSS=${format(memoryUsage.rss)}, HeapTotal=${format(memoryUsage.heapTotal)}, HeapUsed=${format(memoryUsage.heapUsed)}, External=${format(memoryUsage.external)}, ArrayBuffers=${format(memoryUsage.arrayBuffers)}`);
|
|
81
149
|
};
|
|
150
|
+
void printMem;
|
|
82
151
|
// printMem()
|
|
83
152
|
// setInterval(printMem, 5000)
|
|
84
153
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/entrypoints/main.ts"],"names":[],"mappings":";;;;;;;;AACA,OAAO,YAAY,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/entrypoints/main.ts"],"names":[],"mappings":";;;;;;;;AACA,OAAO,YAAY,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,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AAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CACzB,CAAC,KAAK,CAAC,GAAG,EAAE;IACX,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC,CAAC,CAAA;AAEF,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE;IACzC,QAAQ,EAAE,SAAS;IACnB,qBAAqB,EAAE,CAAC;IACxB,IAAI,EAAE,MAAM;CACb,CAAC,CAAA;AAEF,MAAM,QAAQ,GAAG,GAAG,EAAE;IACpB,UAAU,CAAC,EAAE,EAAE,EAAE,CAAA;IACjB,sCAAsC;IACtC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;IACzC,OAAO,CAAC,GAAG,CACT,qBAAqB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,kBAAkB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CACjO,CAAA;AACH,CAAC,CAAA;AACD,KAAK,QAAQ,CAAA;AACb,aAAa;AACb,8BAA8B"}
|
|
@@ -11,46 +11,148 @@ import { workerData as _workerData } from 'node:worker_threads';
|
|
|
11
11
|
const workerData = _workerData;
|
|
12
12
|
const ext = new URL(import.meta.url).pathname.endsWith('.ts') ? '.ts' : '.js';
|
|
13
13
|
const workerPath = fileURLToPath(import.meta.resolve(`./worker${ext}`));
|
|
14
|
+
const kReportedError = Symbol.for('nmtjs.worker.reported-error');
|
|
15
|
+
let runner;
|
|
16
|
+
let workerModule;
|
|
17
|
+
let runtime;
|
|
18
|
+
let runtimeStarted = false;
|
|
14
19
|
process.on('uncaughtException', (error) => {
|
|
15
|
-
|
|
20
|
+
reportError(error, 'runtime', { fatal: true });
|
|
16
21
|
});
|
|
17
22
|
process.on('unhandledRejection', (error) => {
|
|
18
|
-
|
|
23
|
+
reportError(error, 'runtime', { fatal: true });
|
|
19
24
|
});
|
|
20
|
-
process.on('exit',
|
|
21
|
-
|
|
25
|
+
process.on('exit', () => {
|
|
26
|
+
void cleanup();
|
|
22
27
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
async function cleanup() {
|
|
29
|
+
await stopRuntime();
|
|
30
|
+
await closeRunner();
|
|
31
|
+
}
|
|
32
|
+
async function closeRunner() {
|
|
33
|
+
if (!runner)
|
|
34
|
+
return;
|
|
35
|
+
try {
|
|
36
|
+
await runner.close();
|
|
30
37
|
}
|
|
31
|
-
|
|
38
|
+
catch (error) {
|
|
39
|
+
reportError(error, 'runtime', { fatal: false });
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
32
42
|
runner = undefined;
|
|
33
|
-
workerModule = await import(__rewriteRelativeImportExtension(
|
|
34
|
-
/* @vite-ignore */
|
|
35
|
-
workerPath));
|
|
36
43
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
}
|
|
45
|
+
async function stopRuntime() {
|
|
46
|
+
if (!runtime)
|
|
47
|
+
return;
|
|
48
|
+
try {
|
|
49
|
+
if (runtimeStarted) {
|
|
50
|
+
await runtime.stop();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
reportError(error, 'runtime', { fatal: false });
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
runtimeStarted = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function normalizeError(value) {
|
|
61
|
+
if (value instanceof Error)
|
|
62
|
+
return value;
|
|
63
|
+
if (typeof value === 'string')
|
|
64
|
+
return new Error(value);
|
|
65
|
+
if (value && typeof value === 'object') {
|
|
66
|
+
try {
|
|
67
|
+
return new Error(JSON.stringify(value));
|
|
68
|
+
}
|
|
69
|
+
catch { }
|
|
70
|
+
}
|
|
71
|
+
return new Error(String(value));
|
|
72
|
+
}
|
|
73
|
+
function serializeError(error, origin, fatal) {
|
|
74
|
+
return {
|
|
75
|
+
message: error.message,
|
|
76
|
+
name: error.name,
|
|
77
|
+
stack: error.stack,
|
|
78
|
+
origin,
|
|
79
|
+
fatal,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function reportError(value, origin, options = {}) {
|
|
83
|
+
const fatal = options.fatal ?? origin !== 'runtime';
|
|
84
|
+
const error = normalizeError(value);
|
|
85
|
+
if (!error[kReportedError]) {
|
|
86
|
+
try {
|
|
87
|
+
workerData.port.postMessage({
|
|
88
|
+
type: 'error',
|
|
89
|
+
data: serializeError(error, origin, fatal),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch { }
|
|
93
|
+
console.error(new Error(`Worker thread ${origin} error`, { cause: error }));
|
|
94
|
+
error[kReportedError] = true;
|
|
95
|
+
}
|
|
96
|
+
return error;
|
|
97
|
+
}
|
|
98
|
+
async function loadWorkerModule() {
|
|
99
|
+
try {
|
|
100
|
+
if (workerData.vite) {
|
|
101
|
+
const { createModuleRunner } = (await import("../vite/runners/worker.js"));
|
|
102
|
+
runner = createModuleRunner(workerData.vite);
|
|
103
|
+
workerModule = await runner.import(workerPath);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
runner = undefined;
|
|
107
|
+
workerModule = await import(__rewriteRelativeImportExtension(
|
|
108
|
+
/* @vite-ignore */
|
|
109
|
+
workerPath));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw reportError(error, 'bootstrap');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function initializeRuntime() {
|
|
117
|
+
try {
|
|
118
|
+
runtime = await workerModule.run(workerData.runtime);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw reportError(error, 'bootstrap');
|
|
122
|
+
}
|
|
41
123
|
workerData.port.on('message', async (msg) => {
|
|
42
124
|
if (msg.type === 'stop') {
|
|
43
|
-
await
|
|
125
|
+
await cleanup();
|
|
44
126
|
process.exit(0);
|
|
45
127
|
}
|
|
46
128
|
});
|
|
47
|
-
const hosts = (await runtime?.start()) || undefined;
|
|
48
|
-
workerData.port.postMessage({
|
|
49
|
-
type: 'ready',
|
|
50
|
-
data: { hosts },
|
|
51
|
-
});
|
|
52
129
|
}
|
|
53
|
-
|
|
54
|
-
|
|
130
|
+
async function startRuntime() {
|
|
131
|
+
if (!runtime)
|
|
132
|
+
return;
|
|
133
|
+
try {
|
|
134
|
+
const hosts = (await runtime.start()) || undefined;
|
|
135
|
+
runtimeStarted = true;
|
|
136
|
+
workerData.port.postMessage({
|
|
137
|
+
type: 'ready',
|
|
138
|
+
data: { hosts },
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw reportError(error, 'start');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function main() {
|
|
146
|
+
await loadWorkerModule();
|
|
147
|
+
await initializeRuntime();
|
|
148
|
+
await startRuntime();
|
|
55
149
|
}
|
|
150
|
+
main().catch(async (error) => {
|
|
151
|
+
const normalized = error instanceof Error ? error : normalizeError(error);
|
|
152
|
+
if (!normalized[kReportedError]) {
|
|
153
|
+
reportError(normalized, 'bootstrap');
|
|
154
|
+
}
|
|
155
|
+
await cleanup();
|
|
156
|
+
process.exit(1);
|
|
157
|
+
});
|
|
56
158
|
//# sourceMappingURL=thread.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.js","sourceRoot":"","sources":["../../src/entrypoints/thread.ts"],"names":[],"mappings":";;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"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,KAAK,EAAE,EAAE;IAC3B,MAAM,UAAU,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IACzE,IAAI,CAAE,UAAkB,CAAC,cAAc,CAAC,EAAE,CAAC;QACzC,WAAW,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;IACtC,CAAC;IACD,MAAM,OAAO,EAAE,CAAA;IACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
|
@@ -3,7 +3,7 @@ import type { Logger } from '@nmtjs/core';
|
|
|
3
3
|
import type { ProxyableTransportType } from '@nmtjs/gateway';
|
|
4
4
|
import type { ServerConfig } from './config.ts';
|
|
5
5
|
import type { Thread } from './pool.ts';
|
|
6
|
-
import type { ApplicationServerWorkerConfig } from './server.ts';
|
|
6
|
+
import type { ApplicationServerWorkerConfig, ApplicationWorkerErrorEvent, ApplicationWorkerReadyEvent } from './server.ts';
|
|
7
7
|
import { Pool } from './pool.ts';
|
|
8
8
|
export type ApplicationProxyUpstream = {
|
|
9
9
|
type: ProxyableTransportType;
|
|
@@ -42,8 +42,11 @@ export declare class ApplicationServerApplications extends EventEmitter<{
|
|
|
42
42
|
}>;
|
|
43
43
|
serverConfig: ServerConfig;
|
|
44
44
|
});
|
|
45
|
+
get appsNames(): string[];
|
|
45
46
|
start(): Promise<void>;
|
|
46
47
|
stop(): Promise<void>;
|
|
47
48
|
protected addUpstream(application: string, key: string, upstream: ApplicationProxyUpstream): void;
|
|
48
49
|
protected removeThreadUpstreams(thread: Thread): void;
|
|
50
|
+
protected emitWorkerReady(event: ApplicationWorkerReadyEvent): void;
|
|
51
|
+
protected emitWorkerError(event: ApplicationWorkerErrorEvent): void;
|
|
49
52
|
}
|
|
@@ -14,6 +14,9 @@ export class ApplicationServerApplications extends EventEmitter {
|
|
|
14
14
|
workerData: { ...this.params.workerConfig.workerData },
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
get appsNames() {
|
|
18
|
+
return this.params.applications;
|
|
19
|
+
}
|
|
17
20
|
async start() {
|
|
18
21
|
const { logger, applications, applicationsConfig, serverConfig } = this.params;
|
|
19
22
|
for (const applicationName of applications) {
|
|
@@ -41,25 +44,38 @@ export class ApplicationServerApplications extends EventEmitter {
|
|
|
41
44
|
},
|
|
42
45
|
});
|
|
43
46
|
thread.on('ready', ({ hosts }) => {
|
|
44
|
-
|
|
45
|
-
return;
|
|
47
|
+
this.removeThreadUpstreams(thread);
|
|
46
48
|
const keys = [];
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
url.hostname
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
url:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
const sanitizedHosts = [];
|
|
50
|
+
if (hosts?.length) {
|
|
51
|
+
for (const host of hosts) {
|
|
52
|
+
const url = new URL(host.url);
|
|
53
|
+
if (url.hostname === '0.0.0.0')
|
|
54
|
+
url.hostname = '127.0.0.1';
|
|
55
|
+
const normalizedUrl = url.toString();
|
|
56
|
+
sanitizedHosts.push({ type: host.type, url: normalizedUrl });
|
|
57
|
+
const upstream = {
|
|
58
|
+
type: host.type,
|
|
59
|
+
url: normalizedUrl,
|
|
60
|
+
};
|
|
61
|
+
const key = `${upstream.type}:${upstream.url}`;
|
|
62
|
+
keys.push({ application: applicationName, key });
|
|
63
|
+
this.addUpstream(applicationName, key, upstream);
|
|
64
|
+
}
|
|
59
65
|
}
|
|
60
66
|
this.upstreamsByThread.set(thread, keys);
|
|
67
|
+
this.emitWorkerReady({
|
|
68
|
+
application: applicationName,
|
|
69
|
+
threadId: thread.worker.threadId,
|
|
70
|
+
hosts: sanitizedHosts.length ? sanitizedHosts : undefined,
|
|
71
|
+
});
|
|
61
72
|
});
|
|
62
|
-
thread.
|
|
73
|
+
thread.on('error', (error) => {
|
|
74
|
+
this.emitWorkerError({
|
|
75
|
+
application: applicationName,
|
|
76
|
+
threadId: thread.worker.threadId,
|
|
77
|
+
error,
|
|
78
|
+
});
|
|
63
79
|
this.removeThreadUpstreams(thread);
|
|
64
80
|
});
|
|
65
81
|
thread.worker.once('exit', () => {
|
|
@@ -106,5 +122,12 @@ export class ApplicationServerApplications extends EventEmitter {
|
|
|
106
122
|
}
|
|
107
123
|
}
|
|
108
124
|
}
|
|
125
|
+
emitWorkerReady(event) {
|
|
126
|
+
this.params.workerConfig.events?.emit('worker-ready', event);
|
|
127
|
+
}
|
|
128
|
+
emitWorkerError(event) {
|
|
129
|
+
this.params.logger.error(new Error(`Worker [${event.application}] thread ${event.threadId} error`, { cause: event.error }));
|
|
130
|
+
this.params.workerConfig.events?.emit('worker-error', event);
|
|
131
|
+
}
|
|
109
132
|
}
|
|
110
133
|
//# sourceMappingURL=applications.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applications.js","sourceRoot":"","sources":["../../../src/runtime/server/applications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"applications.js","sourceRoot":"","sources":["../../../src/runtime/server/applications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAa1C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAOhC,MAAM,OAAO,6BAA8B,SAAQ,YAGjD;IAaW;IAZX,IAAI,CAAM;IAES,SAAS,GAAG,IAAI,GAAG,EAGnC,CAAA;IACgB,iBAAiB,GAAG,IAAI,OAAO,EAG/C,CAAA;IAEH,YACW,MASR;QAED,KAAK,EAAE,CAAA;QAXE,WAAM,GAAN,MAAM,CASd;QAGD,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC;YACnB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI;YACnC,MAAM,EAAE,IAAI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D,CAAC;IAES,eAAe,CAAC,KAAkC;QAC1D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CACtB,IAAI,KAAK,CACP,WAAW,KAAK,CAAC,WAAW,YAAY,KAAK,CAAC,QAAQ,QAAQ,EAC9D,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CACvB,CACF,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;IAC9D,CAAC;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LoggingOptions } from '@nmtjs/core';
|
|
2
2
|
import type { Transport } from '@nmtjs/gateway';
|
|
3
|
+
import type { ApplicationOptions } from '@nmtjs/proxy';
|
|
3
4
|
import type { Applications } from 'nmtjs/runtime/types';
|
|
4
5
|
import type { ApplicationConfig } from '../application/config.ts';
|
|
5
6
|
import type { JobWorkerPool, StoreType } from '../enums.ts';
|
|
@@ -52,6 +53,9 @@ export interface ServerConfig {
|
|
|
52
53
|
proxy?: {
|
|
53
54
|
port: number;
|
|
54
55
|
hostname: string;
|
|
56
|
+
applications: {
|
|
57
|
+
[K in keyof Applications]?: Omit<ApplicationOptions, 'name'>;
|
|
58
|
+
};
|
|
55
59
|
threads?: number;
|
|
56
60
|
healthChecks?: {
|
|
57
61
|
interval?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/runtime/server/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/runtime/server/config.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAgF/C,MAAM,UAAU,YAAY,CAC1B,OACkE;IAElE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,GACxE,OAAO,CAAA;IACT,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,CAAC,aAAa,CAAC,EAAE,IAAI;QACrB,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,KAAK;QACL,KAAK;QACL,YAAY;QACZ,IAAI;KACI,CAAC,CAAA;AACb,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAU;IACvC,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,aAAa,CAAC,CAAC,CAAA;AACxC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { MessagePort, WorkerOptions } from 'node:worker_threads';
|
|
2
2
|
import EventEmitter from 'node:events';
|
|
3
3
|
import { Worker } from 'node:worker_threads';
|
|
4
|
-
import type { JobTaskResult, ServerPortMessageTypes, ThreadPortMessageTypes, WorkerJobTask } from '../types.ts';
|
|
4
|
+
import type { JobTaskResult, ServerPortMessageTypes, ThreadPortMessageTypes, WorkerJobTask, WorkerThreadError } from '../types.ts';
|
|
5
5
|
export type ThreadState = 'starting' | 'error' | 'terminating' | 'pending' | 'ready';
|
|
6
6
|
export declare class Thread extends EventEmitter<{
|
|
7
|
-
error: [error:
|
|
7
|
+
error: [error: WorkerThreadError];
|
|
8
8
|
ready: [ThreadPortMessageTypes['ready']];
|
|
9
9
|
task: [ThreadPortMessageTypes['task']];
|
|
10
10
|
terminate: [];
|
|
@@ -16,6 +16,8 @@ export declare class Thread extends EventEmitter<{
|
|
|
16
16
|
readonly port: MessagePort;
|
|
17
17
|
worker: Worker;
|
|
18
18
|
state: ThreadState;
|
|
19
|
+
protected readyMessage?: ThreadPortMessageTypes['ready'];
|
|
20
|
+
protected startPromise?: Promise<void>;
|
|
19
21
|
constructor(port: MessagePort, workerPath: string, workerOptions: WorkerOptions);
|
|
20
22
|
start(): Promise<void>;
|
|
21
23
|
stop(): Promise<void>;
|