nmtjs 0.16.1 → 0.17.0-beta.2
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/LICENSE.md +1 -1
- package/README.md +41 -1
- package/dist/index.d.ts +22 -161
- package/dist/index.js +24 -53
- package/dist/index.js.map +1 -1
- package/package.json +11 -63
- package/src/index.ts +71 -91
- package/bin/cli.js +0 -2
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -137
- package/dist/cli.js.map +0 -1
- package/dist/codegen.d.ts +0 -5
- package/dist/codegen.js +0 -18
- package/dist/codegen.js.map +0 -1
- package/dist/config.d.ts +0 -47
- package/dist/config.js +0 -16
- package/dist/config.js.map +0 -1
- package/dist/entrypoints/cli.d.ts +0 -1
- package/dist/entrypoints/cli.js +0 -12
- package/dist/entrypoints/cli.js.map +0 -1
- package/dist/entrypoints/main.d.ts +0 -5
- package/dist/entrypoints/main.js +0 -248
- package/dist/entrypoints/main.js.map +0 -1
- package/dist/entrypoints/thread.d.ts +0 -16
- package/dist/entrypoints/thread.js +0 -182
- package/dist/entrypoints/thread.js.map +0 -1
- package/dist/entrypoints/worker.d.ts +0 -9
- package/dist/entrypoints/worker.js +0 -143
- package/dist/entrypoints/worker.js.map +0 -1
- package/dist/resolver.d.ts +0 -2
- package/dist/resolver.js +0 -7
- package/dist/resolver.js.map +0 -1
- package/dist/runtime/application/index.d.ts +0 -1
- package/dist/runtime/application/index.js +0 -2
- package/dist/runtime/application/index.js.map +0 -1
- package/dist/runtime/constants.d.ts +0 -8
- package/dist/runtime/constants.js +0 -5
- package/dist/runtime/constants.js.map +0 -1
- package/dist/runtime/enums.d.ts +0 -10
- package/dist/runtime/enums.js +0 -13
- package/dist/runtime/enums.js.map +0 -1
- package/dist/runtime/hooks.d.ts +0 -1
- package/dist/runtime/hooks.js +0 -2
- package/dist/runtime/hooks.js.map +0 -1
- package/dist/runtime/index.d.ts +0 -28
- package/dist/runtime/index.js +0 -29
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/injectables.d.ts +0 -69
- package/dist/runtime/injectables.js +0 -40
- package/dist/runtime/injectables.js.map +0 -1
- package/dist/runtime/jobs/job.d.ts +0 -146
- package/dist/runtime/jobs/job.js +0 -89
- package/dist/runtime/jobs/job.js.map +0 -1
- package/dist/runtime/jobs/manager.d.ts +0 -131
- package/dist/runtime/jobs/manager.js +0 -309
- package/dist/runtime/jobs/manager.js.map +0 -1
- package/dist/runtime/jobs/router.d.ts +0 -296
- package/dist/runtime/jobs/router.js +0 -458
- package/dist/runtime/jobs/router.js.map +0 -1
- package/dist/runtime/jobs/runner.d.ts +0 -103
- package/dist/runtime/jobs/runner.js +0 -425
- package/dist/runtime/jobs/runner.js.map +0 -1
- package/dist/runtime/jobs/step.d.ts +0 -26
- package/dist/runtime/jobs/step.js +0 -18
- package/dist/runtime/jobs/step.js.map +0 -1
- package/dist/runtime/jobs/types.d.ts +0 -86
- package/dist/runtime/jobs/types.js +0 -5
- package/dist/runtime/jobs/types.js.map +0 -1
- package/dist/runtime/metrics/metric.d.ts +0 -8
- package/dist/runtime/metrics/metric.js +0 -11
- package/dist/runtime/metrics/metric.js.map +0 -1
- package/dist/runtime/metrics/registry.d.ts +0 -3
- package/dist/runtime/metrics/registry.js +0 -5
- package/dist/runtime/metrics/registry.js.map +0 -1
- package/dist/runtime/metrics/server.d.ts +0 -7
- package/dist/runtime/metrics/server.js +0 -53
- package/dist/runtime/metrics/server.js.map +0 -1
- package/dist/runtime/plugin.d.ts +0 -2
- package/dist/runtime/plugin.js +0 -2
- package/dist/runtime/plugin.js.map +0 -1
- package/dist/runtime/runtime.d.ts +0 -27
- package/dist/runtime/runtime.js +0 -77
- package/dist/runtime/runtime.js.map +0 -1
- package/dist/runtime/scheduler/index.d.ts +0 -22
- package/dist/runtime/scheduler/index.js +0 -20
- package/dist/runtime/scheduler/index.js.map +0 -1
- package/dist/runtime/server/applications.d.ts +0 -91
- package/dist/runtime/server/applications.js +0 -171
- package/dist/runtime/server/applications.js.map +0 -1
- package/dist/runtime/server/config.d.ts +0 -148
- package/dist/runtime/server/config.js +0 -33
- package/dist/runtime/server/config.js.map +0 -1
- package/dist/runtime/server/environment.d.ts +0 -43
- package/dist/runtime/server/environment.js +0 -33
- package/dist/runtime/server/environment.js.map +0 -1
- package/dist/runtime/server/error-policy.d.ts +0 -62
- package/dist/runtime/server/error-policy.js +0 -73
- package/dist/runtime/server/error-policy.js.map +0 -1
- package/dist/runtime/server/hmr-coordinator.d.ts +0 -37
- package/dist/runtime/server/hmr-coordinator.js +0 -94
- package/dist/runtime/server/hmr-coordinator.js.map +0 -1
- package/dist/runtime/server/jobs.d.ts +0 -54
- package/dist/runtime/server/jobs.js +0 -176
- package/dist/runtime/server/jobs.js.map +0 -1
- package/dist/runtime/server/lifecycle.d.ts +0 -85
- package/dist/runtime/server/lifecycle.js +0 -177
- package/dist/runtime/server/lifecycle.js.map +0 -1
- package/dist/runtime/server/managed-worker.d.ts +0 -158
- package/dist/runtime/server/managed-worker.js +0 -420
- package/dist/runtime/server/managed-worker.js.map +0 -1
- package/dist/runtime/server/pool-manager.d.ts +0 -85
- package/dist/runtime/server/pool-manager.js +0 -129
- package/dist/runtime/server/pool-manager.js.map +0 -1
- package/dist/runtime/server/proxy.d.ts +0 -21
- package/dist/runtime/server/proxy.js +0 -76
- package/dist/runtime/server/proxy.js.map +0 -1
- package/dist/runtime/server/server.d.ts +0 -60
- package/dist/runtime/server/server.js +0 -163
- package/dist/runtime/server/server.js.map +0 -1
- package/dist/runtime/server/types.d.ts +0 -31
- package/dist/runtime/server/types.js +0 -2
- package/dist/runtime/server/types.js.map +0 -1
- package/dist/runtime/server/worker-pool.d.ts +0 -121
- package/dist/runtime/server/worker-pool.js +0 -171
- package/dist/runtime/server/worker-pool.js.map +0 -1
- package/dist/runtime/store/index.d.ts +0 -3
- package/dist/runtime/store/index.js +0 -23
- package/dist/runtime/store/index.js.map +0 -1
- package/dist/runtime/subscription/manager.d.ts +0 -49
- package/dist/runtime/subscription/manager.js +0 -170
- package/dist/runtime/subscription/manager.js.map +0 -1
- package/dist/runtime/subscription/redis.d.ts +0 -18
- package/dist/runtime/subscription/redis.js +0 -119
- package/dist/runtime/subscription/redis.js.map +0 -1
- package/dist/runtime/types.d.ts +0 -95
- package/dist/runtime/types.js +0 -2
- package/dist/runtime/types.js.map +0 -1
- package/dist/runtime/workers/application.d.ts +0 -29
- package/dist/runtime/workers/application.js +0 -77
- package/dist/runtime/workers/application.js.map +0 -1
- package/dist/runtime/workers/base.d.ts +0 -14
- package/dist/runtime/workers/base.js +0 -41
- package/dist/runtime/workers/base.js.map +0 -1
- package/dist/runtime/workers/cli.d.ts +0 -1
- package/dist/runtime/workers/cli.js +0 -2
- package/dist/runtime/workers/cli.js.map +0 -1
- package/dist/runtime/workers/job.d.ts +0 -20
- package/dist/runtime/workers/job.js +0 -170
- package/dist/runtime/workers/job.js.map +0 -1
- package/dist/vite/builder.d.ts +0 -5
- package/dist/vite/builder.js +0 -79
- package/dist/vite/builder.js.map +0 -1
- package/dist/vite/config.d.ts +0 -28
- package/dist/vite/config.js +0 -22
- package/dist/vite/config.js.map +0 -1
- package/dist/vite/plugins.d.ts +0 -2
- package/dist/vite/plugins.js +0 -43
- package/dist/vite/plugins.js.map +0 -1
- package/dist/vite/runners/worker.d.ts +0 -3
- package/dist/vite/runners/worker.js +0 -34
- package/dist/vite/runners/worker.js.map +0 -1
- package/dist/vite/server.d.ts +0 -3
- package/dist/vite/server.js +0 -36
- package/dist/vite/server.js.map +0 -1
- package/dist/vite/servers/main.d.ts +0 -8
- package/dist/vite/servers/main.js +0 -24
- package/dist/vite/servers/main.js.map +0 -1
- package/dist/vite/servers/worker.d.ts +0 -13
- package/dist/vite/servers/worker.js +0 -124
- package/dist/vite/servers/worker.js.map +0 -1
- package/src/cli.ts +0 -162
- package/src/codegen.ts +0 -30
- package/src/config.ts +0 -69
- package/src/entrypoints/cli.ts +0 -13
- package/src/entrypoints/main.ts +0 -317
- package/src/entrypoints/thread.ts +0 -223
- package/src/entrypoints/worker.ts +0 -174
- package/src/resolver.ts +0 -7
- package/src/runtime/application/index.ts +0 -1
- package/src/runtime/constants.ts +0 -13
- package/src/runtime/enums.ts +0 -12
- package/src/runtime/hooks.ts +0 -1
- package/src/runtime/index.ts +0 -29
- package/src/runtime/injectables.ts +0 -101
- package/src/runtime/jobs/job.ts +0 -467
- package/src/runtime/jobs/manager.ts +0 -454
- package/src/runtime/jobs/router.ts +0 -967
- package/src/runtime/jobs/runner.ts +0 -583
- package/src/runtime/jobs/step.ts +0 -66
- package/src/runtime/jobs/types.ts +0 -116
- package/src/runtime/metrics/metric.ts +0 -18
- package/src/runtime/metrics/registry.ts +0 -11
- package/src/runtime/metrics/server.ts +0 -69
- package/src/runtime/plugin.ts +0 -2
- package/src/runtime/runtime.ts +0 -103
- package/src/runtime/scheduler/index.ts +0 -39
- package/src/runtime/server/applications.ts +0 -264
- package/src/runtime/server/config.ts +0 -199
- package/src/runtime/server/environment.ts +0 -71
- package/src/runtime/server/error-policy.ts +0 -132
- package/src/runtime/server/hmr-coordinator.ts +0 -116
- package/src/runtime/server/jobs.ts +0 -266
- package/src/runtime/server/lifecycle.ts +0 -234
- package/src/runtime/server/managed-worker.ts +0 -546
- package/src/runtime/server/pool-manager.ts +0 -187
- package/src/runtime/server/proxy.ts +0 -119
- package/src/runtime/server/server.ts +0 -218
- package/src/runtime/server/types.ts +0 -32
- package/src/runtime/server/worker-pool.ts +0 -275
- package/src/runtime/store/index.ts +0 -30
- package/src/runtime/subscription/manager.ts +0 -307
- package/src/runtime/subscription/redis.ts +0 -159
- package/src/runtime/types.ts +0 -84
- package/src/runtime/workers/application.ts +0 -133
- package/src/runtime/workers/base.ts +0 -65
- package/src/runtime/workers/cli.ts +0 -0
- package/src/runtime/workers/job.ts +0 -142
- package/src/vite/builder.ts +0 -94
- package/src/vite/config.ts +0 -45
- package/src/vite/plugins.ts +0 -53
- package/src/vite/runners/worker.ts +0 -55
- package/src/vite/server.ts +0 -55
- package/src/vite/servers/main.ts +0 -41
- package/src/vite/servers/worker.ts +0 -177
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
import EventEmitter, { once } from 'node:events';
|
|
2
|
-
import { MessageChannel, Worker } from 'node:worker_threads';
|
|
3
|
-
const omitExecArgv = ['--expose-gc'];
|
|
4
|
-
/**
|
|
5
|
-
* Time window (ms) after which a worker is considered "stable".
|
|
6
|
-
* Used to reset consecutive failure count.
|
|
7
|
-
*/
|
|
8
|
-
const STABILITY_WINDOW_MS = 30_000;
|
|
9
|
-
/**
|
|
10
|
-
* Worker startup timeout (ms).
|
|
11
|
-
*/
|
|
12
|
-
const STARTUP_TIMEOUT_MS = 15_000;
|
|
13
|
-
/**
|
|
14
|
-
* Worker stop timeout (ms).
|
|
15
|
-
*/
|
|
16
|
-
const STOP_TIMEOUT_MS = 10_000;
|
|
17
|
-
/**
|
|
18
|
-
* ManagedWorker wraps a Node.js Worker thread with:
|
|
19
|
-
* - Explicit state machine
|
|
20
|
-
* - Automatic restart with exponential backoff
|
|
21
|
-
* - Error tracking and stability detection
|
|
22
|
-
* - Integration with ErrorPolicy for restart decisions
|
|
23
|
-
*
|
|
24
|
-
* State Machine:
|
|
25
|
-
* - idle: Initial state, worker not created
|
|
26
|
-
* - starting: Worker created, waiting for ready message
|
|
27
|
-
* - ready: Worker is running and healthy
|
|
28
|
-
* - error: Worker crashed or failed to start
|
|
29
|
-
* - restarting: Worker is scheduled for restart (waiting for delay)
|
|
30
|
-
* - stopping: Worker is being terminated
|
|
31
|
-
* - stopped: Worker has been terminated (terminal state)
|
|
32
|
-
*/
|
|
33
|
-
export class ManagedWorker extends EventEmitter {
|
|
34
|
-
config;
|
|
35
|
-
policy;
|
|
36
|
-
state = 'idle';
|
|
37
|
-
ctx = {
|
|
38
|
-
consecutiveFailures: 0,
|
|
39
|
-
totalFailures: 0,
|
|
40
|
-
lastStableTime: null,
|
|
41
|
-
lastError: null,
|
|
42
|
-
};
|
|
43
|
-
worker = null;
|
|
44
|
-
port = null;
|
|
45
|
-
vitePort = null;
|
|
46
|
-
restartTimer = null;
|
|
47
|
-
startPromise = null;
|
|
48
|
-
pendingTaskIds = new Set();
|
|
49
|
-
logger;
|
|
50
|
-
constructor(config, policy, logger) {
|
|
51
|
-
super();
|
|
52
|
-
this.config = config;
|
|
53
|
-
this.policy = policy;
|
|
54
|
-
this.logger = logger.child({
|
|
55
|
-
component: 'ManagedWorker',
|
|
56
|
-
workerId: config.id,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/** Current worker state */
|
|
60
|
-
get currentState() {
|
|
61
|
-
return this.state;
|
|
62
|
-
}
|
|
63
|
-
/** Whether the worker is healthy (ready state) */
|
|
64
|
-
get isHealthy() {
|
|
65
|
-
return this.state === 'ready';
|
|
66
|
-
}
|
|
67
|
-
/** Get a copy of the worker context */
|
|
68
|
-
get context() {
|
|
69
|
-
return { ...this.ctx };
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Reset failure counts. Called when HMR update comes in to give the worker
|
|
73
|
-
* a fresh start after code has been fixed.
|
|
74
|
-
*/
|
|
75
|
-
resetFailureCount() {
|
|
76
|
-
this.ctx.consecutiveFailures = 0;
|
|
77
|
-
this.ctx.lastError = null;
|
|
78
|
-
}
|
|
79
|
-
/** Get the underlying Worker instance (if exists) */
|
|
80
|
-
getWorker() {
|
|
81
|
-
return this.worker;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Start the worker.
|
|
85
|
-
* Can only be called from 'idle' or 'error' states.
|
|
86
|
-
*/
|
|
87
|
-
async start() {
|
|
88
|
-
if (this.state === 'ready')
|
|
89
|
-
return;
|
|
90
|
-
if (this.startPromise)
|
|
91
|
-
return this.startPromise;
|
|
92
|
-
this.assertState('idle', 'error');
|
|
93
|
-
this.startPromise = this.doStart();
|
|
94
|
-
try {
|
|
95
|
-
await this.startPromise;
|
|
96
|
-
}
|
|
97
|
-
finally {
|
|
98
|
-
this.startPromise = null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Stop the worker.
|
|
103
|
-
* Can be called from any state except 'stopped'.
|
|
104
|
-
* Clears any pending restart timers and rejects pending run() tasks.
|
|
105
|
-
*/
|
|
106
|
-
async stop() {
|
|
107
|
-
this.clearRestartTimer();
|
|
108
|
-
if (this.state === 'stopped')
|
|
109
|
-
return;
|
|
110
|
-
this.transition('stopping');
|
|
111
|
-
// Reject any pending run() calls that are waiting for task results.
|
|
112
|
-
// Without this, callers of pool.run() would hang forever since the
|
|
113
|
-
// port is about to be closed and task-* events will never fire.
|
|
114
|
-
this.rejectPendingTasks();
|
|
115
|
-
try {
|
|
116
|
-
await this.terminateWorker();
|
|
117
|
-
}
|
|
118
|
-
finally {
|
|
119
|
-
this.cleanup();
|
|
120
|
-
this.transition('stopped');
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Run a task on this worker (for job workers).
|
|
125
|
-
* The worker must be in 'ready' state.
|
|
126
|
-
*/
|
|
127
|
-
async run(task) {
|
|
128
|
-
if (this.state !== 'ready' || !this.port) {
|
|
129
|
-
throw new Error('Worker is not ready to run tasks');
|
|
130
|
-
}
|
|
131
|
-
const id = crypto.randomUUID();
|
|
132
|
-
this.pendingTaskIds.add(id);
|
|
133
|
-
this.send('task', { id, task });
|
|
134
|
-
try {
|
|
135
|
-
const [result] = (await once(this, `task-${id}`));
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
finally {
|
|
139
|
-
this.pendingTaskIds.delete(id);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Send a message to the worker.
|
|
144
|
-
*/
|
|
145
|
-
send(type, ...[data]) {
|
|
146
|
-
this.port?.postMessage({ type, data });
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Internal: Start the worker and wait for it to be ready.
|
|
150
|
-
*/
|
|
151
|
-
async doStart() {
|
|
152
|
-
this.transition('starting');
|
|
153
|
-
try {
|
|
154
|
-
const { port1, port2 } = new MessageChannel();
|
|
155
|
-
this.port = port1;
|
|
156
|
-
const viteChannel = this.config.onWorker ? new MessageChannel() : null;
|
|
157
|
-
this.vitePort = viteChannel?.port1 ?? null;
|
|
158
|
-
const { config } = this;
|
|
159
|
-
this.worker = new Worker(config.path, {
|
|
160
|
-
...config.workerOptions,
|
|
161
|
-
execArgv: process.execArgv.filter((f) => !omitExecArgv.includes(f)),
|
|
162
|
-
workerData: {
|
|
163
|
-
...config.workerData,
|
|
164
|
-
port: port2,
|
|
165
|
-
vitePort: viteChannel?.port2,
|
|
166
|
-
},
|
|
167
|
-
name: `${config.name}-${config.index + 1}`,
|
|
168
|
-
transferList: viteChannel ? [port2, viteChannel.port2] : [port2],
|
|
169
|
-
});
|
|
170
|
-
// Notify callback if provided
|
|
171
|
-
config.onWorker?.({
|
|
172
|
-
worker: this.worker,
|
|
173
|
-
vitePort: this.vitePort ?? undefined,
|
|
174
|
-
});
|
|
175
|
-
// Set up message handling
|
|
176
|
-
this.attachListeners();
|
|
177
|
-
// Wait for ready with timeout
|
|
178
|
-
await this.waitForReady();
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
this.handleError(error);
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Wait for the worker to emit a 'ready' message or timeout.
|
|
187
|
-
*/
|
|
188
|
-
waitForReady() {
|
|
189
|
-
return new Promise((resolve, reject) => {
|
|
190
|
-
let settled = false;
|
|
191
|
-
let timer;
|
|
192
|
-
const cleanup = () => {
|
|
193
|
-
if (settled)
|
|
194
|
-
return;
|
|
195
|
-
settled = true;
|
|
196
|
-
clearTimeout(timer);
|
|
197
|
-
this.off('ready', handleReady);
|
|
198
|
-
this.off('error', handleError);
|
|
199
|
-
};
|
|
200
|
-
const handleReady = () => {
|
|
201
|
-
cleanup();
|
|
202
|
-
resolve();
|
|
203
|
-
};
|
|
204
|
-
const handleError = (error) => {
|
|
205
|
-
cleanup();
|
|
206
|
-
reject(error);
|
|
207
|
-
};
|
|
208
|
-
this.once('ready', handleReady);
|
|
209
|
-
this.once('error', handleError);
|
|
210
|
-
timer = setTimeout(() => {
|
|
211
|
-
const error = createWorkerThreadError({
|
|
212
|
-
message: `Worker thread ${this.config.id} did not become ready in time`,
|
|
213
|
-
name: 'WorkerStartupTimeoutError',
|
|
214
|
-
origin: 'start',
|
|
215
|
-
fatal: true,
|
|
216
|
-
});
|
|
217
|
-
cleanup();
|
|
218
|
-
this.handleError(error);
|
|
219
|
-
reject(error);
|
|
220
|
-
}, STARTUP_TIMEOUT_MS);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Attach listeners for port and worker events.
|
|
225
|
-
*/
|
|
226
|
-
attachListeners() {
|
|
227
|
-
if (!this.port || !this.worker)
|
|
228
|
-
return;
|
|
229
|
-
this.port.on('message', (msg) => {
|
|
230
|
-
const { type, data } = msg;
|
|
231
|
-
switch (type) {
|
|
232
|
-
case 'ready':
|
|
233
|
-
this.handleReady(data.hosts);
|
|
234
|
-
break;
|
|
235
|
-
case 'error': {
|
|
236
|
-
const error = createWorkerThreadError(data);
|
|
237
|
-
this.handleError(error);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case 'task': {
|
|
241
|
-
const taskData = data;
|
|
242
|
-
this.emit('task', taskData);
|
|
243
|
-
this.emit(`task-${taskData.id}`, taskData.task);
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
this.worker.once('exit', (code) => {
|
|
249
|
-
// Ignore if we're already stopping/stopped
|
|
250
|
-
if (this.state === 'stopping' || this.state === 'stopped')
|
|
251
|
-
return;
|
|
252
|
-
const error = createWorkerThreadError({
|
|
253
|
-
message: `Worker thread ${this.config.id} exited unexpectedly with code ${code}`,
|
|
254
|
-
name: 'WorkerThreadExitError',
|
|
255
|
-
origin: 'runtime',
|
|
256
|
-
fatal: code !== 0,
|
|
257
|
-
});
|
|
258
|
-
this.handleError(error);
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Handle worker ready event.
|
|
263
|
-
*/
|
|
264
|
-
handleReady(hosts) {
|
|
265
|
-
// Check if worker was stable before this (for failure count reset)
|
|
266
|
-
if (this.ctx.lastStableTime !== null &&
|
|
267
|
-
Date.now() - this.ctx.lastStableTime > STABILITY_WINDOW_MS) {
|
|
268
|
-
this.ctx.consecutiveFailures = 0;
|
|
269
|
-
}
|
|
270
|
-
this.ctx.lastStableTime = Date.now();
|
|
271
|
-
this.transition('ready');
|
|
272
|
-
this.emit('ready', hosts);
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Handle worker error.
|
|
276
|
-
*/
|
|
277
|
-
handleError(error) {
|
|
278
|
-
const workerError = error;
|
|
279
|
-
this.ctx.lastError = error;
|
|
280
|
-
this.ctx.consecutiveFailures++;
|
|
281
|
-
this.ctx.totalFailures++;
|
|
282
|
-
this.transition('error');
|
|
283
|
-
if (this.listenerCount('error') > 0) {
|
|
284
|
-
this.emit('error', workerError);
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
this.logger.error(workerError);
|
|
288
|
-
}
|
|
289
|
-
// Unblock any pending run() callers waiting for task-* events.
|
|
290
|
-
// On runtime errors the current worker may never emit task completion.
|
|
291
|
-
this.rejectPendingTasks();
|
|
292
|
-
// Cleanup old worker
|
|
293
|
-
this.terminateWorker().catch(() => { });
|
|
294
|
-
this.cleanup();
|
|
295
|
-
// Consult policy for action
|
|
296
|
-
const errorContext = {
|
|
297
|
-
workerId: this.config.id,
|
|
298
|
-
workerType: this.config.workerType,
|
|
299
|
-
consecutiveFailures: this.ctx.consecutiveFailures,
|
|
300
|
-
totalFailures: this.ctx.totalFailures,
|
|
301
|
-
lastStableTime: this.ctx.lastStableTime,
|
|
302
|
-
};
|
|
303
|
-
const action = this.policy.onWorkerError(workerError, errorContext);
|
|
304
|
-
switch (action.type) {
|
|
305
|
-
case 'restart':
|
|
306
|
-
this.scheduleRestart(action.delay);
|
|
307
|
-
break;
|
|
308
|
-
case 'exit':
|
|
309
|
-
this.logger.fatal(new Error('Worker failed, exiting process', { cause: error }));
|
|
310
|
-
process.exit(action.code);
|
|
311
|
-
break;
|
|
312
|
-
case 'wait':
|
|
313
|
-
this.logger.debug('Worker failed, waiting for fix via HMR');
|
|
314
|
-
break;
|
|
315
|
-
case 'ignore':
|
|
316
|
-
this.logger.warn({ error }, 'Worker error ignored');
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Schedule a restart after the given delay.
|
|
322
|
-
*/
|
|
323
|
-
scheduleRestart(delay) {
|
|
324
|
-
this.transition('restarting');
|
|
325
|
-
this.logger.debug({ delay, attempt: this.ctx.consecutiveFailures }, 'Scheduling worker restart');
|
|
326
|
-
this.restartTimer = setTimeout(() => {
|
|
327
|
-
this.restartTimer = null;
|
|
328
|
-
// Reset to idle before starting
|
|
329
|
-
this.transition('idle');
|
|
330
|
-
this.start().catch((error) => {
|
|
331
|
-
this.logger.error(new Error('Restart failed', { cause: error }));
|
|
332
|
-
});
|
|
333
|
-
}, delay);
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Clear any pending restart timer.
|
|
337
|
-
*/
|
|
338
|
-
clearRestartTimer() {
|
|
339
|
-
if (this.restartTimer) {
|
|
340
|
-
clearTimeout(this.restartTimer);
|
|
341
|
-
this.restartTimer = null;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Terminate the underlying worker thread.
|
|
346
|
-
*/
|
|
347
|
-
async terminateWorker() {
|
|
348
|
-
if (!this.worker)
|
|
349
|
-
return;
|
|
350
|
-
const timeout = STOP_TIMEOUT_MS;
|
|
351
|
-
try {
|
|
352
|
-
const signal = AbortSignal.timeout(timeout);
|
|
353
|
-
const exitPromise = once(this.worker, 'exit', { signal });
|
|
354
|
-
this.send('stop');
|
|
355
|
-
this.port?.close();
|
|
356
|
-
await exitPromise;
|
|
357
|
-
}
|
|
358
|
-
catch {
|
|
359
|
-
this.logger.warn(`Worker thread ${this.config.id} did not terminate in time, forcing termination`);
|
|
360
|
-
await this.worker.terminate();
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Cleanup internal state.
|
|
365
|
-
*/
|
|
366
|
-
cleanup() {
|
|
367
|
-
this.port?.close();
|
|
368
|
-
this.vitePort?.close();
|
|
369
|
-
this.worker = null;
|
|
370
|
-
this.port = null;
|
|
371
|
-
this.vitePort = null;
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Reject all pending run() calls by emitting an error result
|
|
375
|
-
* for each tracked task id. This unblocks callers waiting on
|
|
376
|
-
* `once(this, 'task-<id>')` so they don't hang during shutdown.
|
|
377
|
-
*/
|
|
378
|
-
rejectPendingTasks() {
|
|
379
|
-
for (const id of this.pendingTaskIds) {
|
|
380
|
-
const result = {
|
|
381
|
-
type: 'error',
|
|
382
|
-
error: new Error('Worker is shutting down'),
|
|
383
|
-
};
|
|
384
|
-
this.emit(`task-${id}`, result);
|
|
385
|
-
}
|
|
386
|
-
this.pendingTaskIds.clear();
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Transition to a new state, emitting the state-change event.
|
|
390
|
-
*/
|
|
391
|
-
transition(to) {
|
|
392
|
-
const from = this.state;
|
|
393
|
-
this.state = to;
|
|
394
|
-
this.logger.trace({ from, to }, 'Worker state transition');
|
|
395
|
-
this.emit('state-change', from, to);
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Assert that the current state is one of the allowed states.
|
|
399
|
-
*/
|
|
400
|
-
assertState(...allowed) {
|
|
401
|
-
if (!allowed.includes(this.state)) {
|
|
402
|
-
throw new Error(`Invalid worker state: ${this.state}, expected one of: ${allowed.join(', ')}`);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Create a WorkerThreadError from a message.
|
|
408
|
-
*/
|
|
409
|
-
function createWorkerThreadError(message, includeStack = true) {
|
|
410
|
-
const error = new Error(message.message);
|
|
411
|
-
if (message.name)
|
|
412
|
-
error.name = message.name;
|
|
413
|
-
if (includeStack && message.stack) {
|
|
414
|
-
error.stack = message.stack;
|
|
415
|
-
}
|
|
416
|
-
error.origin = message.origin;
|
|
417
|
-
error.fatal = message.fatal;
|
|
418
|
-
return error;
|
|
419
|
-
}
|
|
420
|
-
//# sourceMappingURL=managed-worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"managed-worker.js","sourceRoot":"","sources":["../../../src/runtime/server/managed-worker.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAgB5D,MAAM,YAAY,GAAG,CAAC,aAAa,CAAC,CAAA;AAgDpC;;;GAGG;AACH,MAAM,mBAAmB,GAAG,MAAM,CAAA;AAElC;;GAEG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAA;AAEjC;;GAEG;AACH,MAAM,eAAe,GAAG,MAAM,CAAA;AAE9B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAiC;IAiBvD,MAAM;IACI,MAAM;IAjBjB,KAAK,GAAgB,MAAM,CAAA;IAC3B,GAAG,GAAyB;QACpC,mBAAmB,EAAE,CAAC;QACtB,aAAa,EAAE,CAAC;QAChB,cAAc,EAAE,IAAI;QACpB,SAAS,EAAE,IAAI;KAChB,CAAA;IACS,MAAM,GAAkB,IAAI,CAAA;IAC5B,IAAI,GAAuB,IAAI,CAAA;IAC/B,QAAQ,GAAuB,IAAI,CAAA;IACnC,YAAY,GAAyC,IAAI,CAAA;IACz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,CAAC,KAAK,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CACb,yBAAyB,IAAI,CAAC,KAAK,sBAAsB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC9E,CAAA;QACH,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,SAAS,uBAAuB,CAC9B,OAA2B,EAC3B,YAAY,GAAG,IAAI;IAEnB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAsB,CAAA;IAC7D,IAAI,OAAO,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IAC3C,IAAI,YAAY,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClC,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;IAC7B,CAAC;IACD,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAC7B,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;IAC3B,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
import type { Logger } from '@nmtjs/core';
|
|
3
|
-
import type { ErrorPolicy } from './error-policy.ts';
|
|
4
|
-
import type { ManagedWorkerFactory, PoolHealth, PoolHealthReport, WorkerPool, WorkerPoolConfig, WorkerPoolFactory } from './worker-pool.ts';
|
|
5
|
-
/**
|
|
6
|
-
* Overall server health state.
|
|
7
|
-
*/
|
|
8
|
-
export type ServerHealth = 'healthy' | 'degraded' | 'unhealthy';
|
|
9
|
-
/**
|
|
10
|
-
* Report on overall server health including all pools.
|
|
11
|
-
*/
|
|
12
|
-
export interface ServerHealthReport {
|
|
13
|
-
overall: ServerHealth;
|
|
14
|
-
pools: PoolHealthReport[];
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Events emitted by PoolManager.
|
|
18
|
-
*/
|
|
19
|
-
export interface PoolManagerEvents {
|
|
20
|
-
'health-change': [health: ServerHealth];
|
|
21
|
-
'pool-health-change': [poolName: string, health: PoolHealth];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* PoolManager manages multiple application pools with aggregate health tracking.
|
|
25
|
-
*
|
|
26
|
-
* Features:
|
|
27
|
-
* - Creates and manages WorkerPools for each application/job type
|
|
28
|
-
* - Aggregates health across all pools
|
|
29
|
-
* - Provides server-level health reports
|
|
30
|
-
*
|
|
31
|
-
* Each application gets its own pool for isolated failure domains.
|
|
32
|
-
* For example, if "api" is degraded but "admin" is healthy, they're tracked independently.
|
|
33
|
-
*/
|
|
34
|
-
export declare class PoolManager extends EventEmitter<PoolManagerEvents> {
|
|
35
|
-
private readonly policy;
|
|
36
|
-
private readonly workerFactory;
|
|
37
|
-
private readonly poolFactory;
|
|
38
|
-
private pools;
|
|
39
|
-
private health;
|
|
40
|
-
private logger;
|
|
41
|
-
constructor(policy: ErrorPolicy, workerFactory: ManagedWorkerFactory, poolFactory: WorkerPoolFactory, logger: Logger);
|
|
42
|
-
/** Current overall server health */
|
|
43
|
-
get currentHealth(): ServerHealth;
|
|
44
|
-
/** Number of pools managed */
|
|
45
|
-
get poolCount(): number;
|
|
46
|
-
/**
|
|
47
|
-
* Create a new pool for an application or job type.
|
|
48
|
-
*
|
|
49
|
-
* @param config - Pool configuration
|
|
50
|
-
* @returns The created WorkerPool
|
|
51
|
-
* @throws If a pool with this name already exists
|
|
52
|
-
*/
|
|
53
|
-
createPool(config: WorkerPoolConfig): WorkerPool;
|
|
54
|
-
/**
|
|
55
|
-
* Get a pool by name.
|
|
56
|
-
*/
|
|
57
|
-
getPool(name: string): WorkerPool | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* Get all pools.
|
|
60
|
-
*/
|
|
61
|
-
getAllPools(): Map<string, WorkerPool>;
|
|
62
|
-
/**
|
|
63
|
-
* Start all pools.
|
|
64
|
-
*/
|
|
65
|
-
startAll(): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Stop all pools.
|
|
68
|
-
*/
|
|
69
|
-
stopAll(): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Get a health report for all pools.
|
|
72
|
-
* This is for internal debugging/logging only.
|
|
73
|
-
* External health checks should use application-level procedures
|
|
74
|
-
* or external monitoring (k8s probes, process monitors).
|
|
75
|
-
*/
|
|
76
|
-
getHealthReport(): ServerHealthReport;
|
|
77
|
-
/**
|
|
78
|
-
* Update overall server health based on pool states.
|
|
79
|
-
*/
|
|
80
|
-
private updateHealth;
|
|
81
|
-
/**
|
|
82
|
-
* Set the health state, emitting event if changed.
|
|
83
|
-
*/
|
|
84
|
-
private setHealth;
|
|
85
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
/**
|
|
3
|
-
* PoolManager manages multiple application pools with aggregate health tracking.
|
|
4
|
-
*
|
|
5
|
-
* Features:
|
|
6
|
-
* - Creates and manages WorkerPools for each application/job type
|
|
7
|
-
* - Aggregates health across all pools
|
|
8
|
-
* - Provides server-level health reports
|
|
9
|
-
*
|
|
10
|
-
* Each application gets its own pool for isolated failure domains.
|
|
11
|
-
* For example, if "api" is degraded but "admin" is healthy, they're tracked independently.
|
|
12
|
-
*/
|
|
13
|
-
export class PoolManager extends EventEmitter {
|
|
14
|
-
policy;
|
|
15
|
-
workerFactory;
|
|
16
|
-
poolFactory;
|
|
17
|
-
pools = new Map();
|
|
18
|
-
health = 'healthy';
|
|
19
|
-
logger;
|
|
20
|
-
constructor(policy, workerFactory, poolFactory, logger) {
|
|
21
|
-
super();
|
|
22
|
-
this.policy = policy;
|
|
23
|
-
this.workerFactory = workerFactory;
|
|
24
|
-
this.poolFactory = poolFactory;
|
|
25
|
-
this.logger = logger.child({ component: 'PoolManager' });
|
|
26
|
-
}
|
|
27
|
-
/** Current overall server health */
|
|
28
|
-
get currentHealth() {
|
|
29
|
-
return this.health;
|
|
30
|
-
}
|
|
31
|
-
/** Number of pools managed */
|
|
32
|
-
get poolCount() {
|
|
33
|
-
return this.pools.size;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Create a new pool for an application or job type.
|
|
37
|
-
*
|
|
38
|
-
* @param config - Pool configuration
|
|
39
|
-
* @returns The created WorkerPool
|
|
40
|
-
* @throws If a pool with this name already exists
|
|
41
|
-
*/
|
|
42
|
-
createPool(config) {
|
|
43
|
-
if (this.pools.has(config.name)) {
|
|
44
|
-
throw new Error(`Pool for "${config.name}" already exists`);
|
|
45
|
-
}
|
|
46
|
-
const pool = this.poolFactory(config, this.policy, this.workerFactory, this.logger);
|
|
47
|
-
pool.on('health-change', (health) => {
|
|
48
|
-
this.emit('pool-health-change', config.name, health);
|
|
49
|
-
this.updateHealth();
|
|
50
|
-
});
|
|
51
|
-
this.pools.set(config.name, pool);
|
|
52
|
-
this.logger.debug({ pool: config.name }, 'Pool created');
|
|
53
|
-
return pool;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get a pool by name.
|
|
57
|
-
*/
|
|
58
|
-
getPool(name) {
|
|
59
|
-
return this.pools.get(name);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get all pools.
|
|
63
|
-
*/
|
|
64
|
-
getAllPools() {
|
|
65
|
-
return new Map(this.pools);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Start all pools.
|
|
69
|
-
*/
|
|
70
|
-
async startAll() {
|
|
71
|
-
this.logger.debug({ count: this.pools.size }, 'Starting all pools');
|
|
72
|
-
await Promise.all([...this.pools.values()].map((p) => p.startAll()));
|
|
73
|
-
this.logger.debug({ count: this.pools.size }, 'All pools started');
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Stop all pools.
|
|
77
|
-
*/
|
|
78
|
-
async stopAll() {
|
|
79
|
-
this.logger.debug({ count: this.pools.size }, 'Stopping all pools');
|
|
80
|
-
await Promise.all([...this.pools.values()].map((p) => p.stopAll()));
|
|
81
|
-
this.pools.clear();
|
|
82
|
-
this.logger.debug('All pools stopped');
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Get a health report for all pools.
|
|
86
|
-
* This is for internal debugging/logging only.
|
|
87
|
-
* External health checks should use application-level procedures
|
|
88
|
-
* or external monitoring (k8s probes, process monitors).
|
|
89
|
-
*/
|
|
90
|
-
getHealthReport() {
|
|
91
|
-
const poolReports = [...this.pools.values()].map((p) => p.getHealthReport());
|
|
92
|
-
return { overall: this.health, pools: poolReports };
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Update overall server health based on pool states.
|
|
96
|
-
*/
|
|
97
|
-
updateHealth() {
|
|
98
|
-
const poolHealths = [...this.pools.values()].map((p) => p.currentHealth);
|
|
99
|
-
// No pools = healthy
|
|
100
|
-
if (poolHealths.length === 0) {
|
|
101
|
-
this.setHealth('healthy');
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
let newHealth;
|
|
105
|
-
if (poolHealths.every((h) => h === 'healthy')) {
|
|
106
|
-
newHealth = 'healthy';
|
|
107
|
-
}
|
|
108
|
-
else if (poolHealths.some((h) => h !== 'unhealthy') &&
|
|
109
|
-
this.policy.allowDegradedMode) {
|
|
110
|
-
newHealth = 'degraded';
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
newHealth = 'unhealthy';
|
|
114
|
-
}
|
|
115
|
-
this.setHealth(newHealth);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Set the health state, emitting event if changed.
|
|
119
|
-
*/
|
|
120
|
-
setHealth(newHealth) {
|
|
121
|
-
if (newHealth !== this.health) {
|
|
122
|
-
const oldHealth = this.health;
|
|
123
|
-
this.health = newHealth;
|
|
124
|
-
this.logger.info({ from: oldHealth, to: newHealth }, 'Server health changed');
|
|
125
|
-
this.emit('health-change', newHealth);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=pool-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pool-manager.js","sourceRoot":"","sources":["../../../src/runtime/server/pool-manager.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAA;AAmCtC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,WAAY,SAAQ,YAA+B;IAM3C,MAAM;IACN,aAAa;IACb,WAAW;IAPtB,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAA;IACrC,MAAM,GAAiB,SAAS,CAAA;IAChC,MAAM,CAAQ;IAEtB,YACmB,MAAmB,EACnB,aAAmC,EACnC,WAA8B,EAC/C,MAAc;QAEd,KAAK,EAAE,CAAA;sBALU,MAAM;6BACN,aAAa;2BACb,WAAW;QAI5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAA;IAC1D,CAAC;IAED,oCAAoC;IACpC,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,8BAA8B;IAC9B,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;IACxB,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,MAAwB;QACjC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,aAAa,MAAM,CAAC,IAAI,kBAAkB,CAAC,CAAA;QAC7D,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAC3B,MAAM,EACN,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,MAAM,CACZ,CAAA;QAED,IAAI,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,EAAE;YAClC,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,EAA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QAED,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;IAC3B,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,SAAuB;QACvC,IAAI,SAAS,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAA;YAC7B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;YACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAClC,uBAAuB,CACxB,CAAA;YACD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '@nmtjs/core';
|
|
2
|
-
import { Proxy as NeemataProxy } from '@nmtjs/proxy';
|
|
3
|
-
import type { ApplicationProxyUpstream, ApplicationServerApplications } from './applications.ts';
|
|
4
|
-
import type { ServerConfig } from './config.ts';
|
|
5
|
-
export declare class ApplicationServerProxy {
|
|
6
|
-
readonly params: {
|
|
7
|
-
logger: Logger;
|
|
8
|
-
config: ServerConfig['proxy'];
|
|
9
|
-
applications: ApplicationServerApplications;
|
|
10
|
-
};
|
|
11
|
-
proxyServer: NeemataProxy;
|
|
12
|
-
protected readonly onAdd: (application: string, upstream: ApplicationProxyUpstream) => void;
|
|
13
|
-
protected readonly onRemove: (application: string, upstream: ApplicationProxyUpstream) => void;
|
|
14
|
-
constructor(params: {
|
|
15
|
-
logger: Logger;
|
|
16
|
-
config: ServerConfig['proxy'];
|
|
17
|
-
applications: ApplicationServerApplications;
|
|
18
|
-
});
|
|
19
|
-
start(): Promise<void>;
|
|
20
|
-
stop(): Promise<void>;
|
|
21
|
-
}
|