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,76 +0,0 @@
|
|
|
1
|
-
import { Proxy as NeemataProxy } from '@nmtjs/proxy';
|
|
2
|
-
/**
|
|
3
|
-
* Transform ApplicationProxyUpstream to the format expected by Rust proxy.
|
|
4
|
-
*/
|
|
5
|
-
function toProxyUpstream(upstream) {
|
|
6
|
-
const url = new URL(upstream.url);
|
|
7
|
-
const secure = url.protocol === 'https:' || url.protocol === 'wss:';
|
|
8
|
-
const port = url.port ? Number.parseInt(url.port, 10) : secure ? 443 : 80;
|
|
9
|
-
return {
|
|
10
|
-
type: 'port',
|
|
11
|
-
transport: upstream.type,
|
|
12
|
-
secure,
|
|
13
|
-
hostname: url.hostname,
|
|
14
|
-
port,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export class ApplicationServerProxy {
|
|
18
|
-
params;
|
|
19
|
-
proxyServer;
|
|
20
|
-
onAdd;
|
|
21
|
-
onRemove;
|
|
22
|
-
constructor(params) {
|
|
23
|
-
this.params = params;
|
|
24
|
-
const { config } = params;
|
|
25
|
-
if (!config) {
|
|
26
|
-
throw new Error('Proxy config is required');
|
|
27
|
-
}
|
|
28
|
-
this.proxyServer = new NeemataProxy({
|
|
29
|
-
listen: `${config.hostname}:${config.port}`,
|
|
30
|
-
tls: config.tls
|
|
31
|
-
? { keyPath: config.tls.key, certPath: config.tls.cert }
|
|
32
|
-
: undefined,
|
|
33
|
-
applications: Object.entries(config.applications)
|
|
34
|
-
.filter(([_, options]) => options !== undefined)
|
|
35
|
-
.map(([app, options]) => ({
|
|
36
|
-
name: app,
|
|
37
|
-
routing: options.routing,
|
|
38
|
-
sni: options.sni,
|
|
39
|
-
})),
|
|
40
|
-
});
|
|
41
|
-
this.onAdd = (application, upstream) => {
|
|
42
|
-
const proxyUpstream = toProxyUpstream(upstream);
|
|
43
|
-
this.params.logger.debug({ application, upstream: proxyUpstream }, 'Adding upstream to proxy');
|
|
44
|
-
this.proxyServer
|
|
45
|
-
.addUpstream(application, proxyUpstream)
|
|
46
|
-
.catch((error) => {
|
|
47
|
-
this.params.logger.warn({ error, application, upstream: proxyUpstream }, 'Failed to add upstream to proxy');
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
this.onRemove = (application, upstream) => {
|
|
51
|
-
const proxyUpstream = toProxyUpstream(upstream);
|
|
52
|
-
this.params.logger.debug({ application, upstream: proxyUpstream }, 'Removing upstream from proxy');
|
|
53
|
-
this.proxyServer
|
|
54
|
-
.removeUpstream(application, proxyUpstream)
|
|
55
|
-
.catch((error) => {
|
|
56
|
-
this.params.logger.warn({ error, application, upstream: proxyUpstream }, 'Failed to remove upstream from proxy');
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
params.applications.on('add', this.onAdd);
|
|
60
|
-
params.applications.on('remove', this.onRemove);
|
|
61
|
-
}
|
|
62
|
-
async start() {
|
|
63
|
-
const { config } = this.params;
|
|
64
|
-
if (!config) {
|
|
65
|
-
throw new Error('Proxy config is required');
|
|
66
|
-
}
|
|
67
|
-
this.params.logger.info({ hostname: config.hostname, port: config.port, threads: config.threads }, 'Proxy configuration');
|
|
68
|
-
await this.proxyServer.start();
|
|
69
|
-
}
|
|
70
|
-
async stop() {
|
|
71
|
-
this.params.applications.off('add', this.onAdd);
|
|
72
|
-
this.params.applications.off('remove', this.onRemove);
|
|
73
|
-
await this.proxyServer.stop();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=proxy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/runtime/server/proxy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;AAQpD;;GAEG;AACH,SAAS,eAAe,CAAC,QAAkC;IACzD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,C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CAAC,CAAA;QACN,CAAC,CAAA;QAED,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QACzC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjD,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAC9B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7C,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CACrB,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EACzE,qBAAqB,CACtB,CAAA;QACD,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QAC/C,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAErD,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAA;IAC/B,CAAC;CACF"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '@nmtjs/core';
|
|
2
|
-
import type { MetricsServer } from '../metrics/server.ts';
|
|
3
|
-
import type { Store } from '../types.ts';
|
|
4
|
-
import type { ServerConfig } from './config.ts';
|
|
5
|
-
import type { ErrorPolicy } from './error-policy.ts';
|
|
6
|
-
import type { ApplicationServerRunOptions, ApplicationServerWorkerConfig } from './types.ts';
|
|
7
|
-
import type { ManagedWorkerFactory, WorkerPoolFactory } from './worker-pool.ts';
|
|
8
|
-
import { ApplicationServerApplications } from './applications.ts';
|
|
9
|
-
import { ApplicationServerJobs } from './jobs.ts';
|
|
10
|
-
import { ApplicationServerProxy } from './proxy.ts';
|
|
11
|
-
/**
|
|
12
|
-
* Default factory for creating ManagedWorker instances.
|
|
13
|
-
*/
|
|
14
|
-
export declare const defaultWorkerFactory: ManagedWorkerFactory;
|
|
15
|
-
/**
|
|
16
|
-
* Default factory for creating WorkerPool instances.
|
|
17
|
-
*/
|
|
18
|
-
export declare const defaultPoolFactory: WorkerPoolFactory;
|
|
19
|
-
/**
|
|
20
|
-
* ApplicationServer is the main server orchestrator.
|
|
21
|
-
*
|
|
22
|
-
* It manages:
|
|
23
|
-
* - Application worker pools
|
|
24
|
-
* - Job runner pools
|
|
25
|
-
* - Reverse proxy
|
|
26
|
-
* - Store connections
|
|
27
|
-
*
|
|
28
|
-
* The server integrates with ErrorPolicy for proper error handling
|
|
29
|
-
* and uses ManagedWorker for worker lifecycle management.
|
|
30
|
-
*/
|
|
31
|
-
export declare class ApplicationServer {
|
|
32
|
-
readonly config: ServerConfig;
|
|
33
|
-
readonly applicationsConfig: Record<string, {
|
|
34
|
-
type: 'neemata' | 'custom';
|
|
35
|
-
specifier: string;
|
|
36
|
-
}>;
|
|
37
|
-
readonly workerConfig: ApplicationServerWorkerConfig;
|
|
38
|
-
readonly runOptions: ApplicationServerRunOptions;
|
|
39
|
-
readonly errorPolicy: ErrorPolicy;
|
|
40
|
-
readonly workerFactory: ManagedWorkerFactory;
|
|
41
|
-
readonly poolFactory: WorkerPoolFactory;
|
|
42
|
-
logger: Logger;
|
|
43
|
-
applications?: ApplicationServerApplications;
|
|
44
|
-
jobRunners?: ApplicationServerJobs;
|
|
45
|
-
proxy?: ApplicationServerProxy;
|
|
46
|
-
store?: Store;
|
|
47
|
-
metrics?: MetricsServer;
|
|
48
|
-
constructor(config: ServerConfig, applicationsConfig: Record<string, {
|
|
49
|
-
type: 'neemata' | 'custom';
|
|
50
|
-
specifier: string;
|
|
51
|
-
}>, workerConfig: ApplicationServerWorkerConfig, runOptions?: ApplicationServerRunOptions, errorPolicy?: ErrorPolicy, workerFactory?: ManagedWorkerFactory, poolFactory?: WorkerPoolFactory);
|
|
52
|
-
start(): Promise<void>;
|
|
53
|
-
stop(): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Restart failed workers across all pools.
|
|
56
|
-
* Called when HMR update comes in and workers may have failed.
|
|
57
|
-
* @returns Number of workers that were restarted
|
|
58
|
-
*/
|
|
59
|
-
restartFailedWorkers(): Promise<number>;
|
|
60
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@nmtjs/core';
|
|
2
|
-
import { createMetricsServer } from '../metrics/server.js';
|
|
3
|
-
import { createStoreClient } from '../store/index.js';
|
|
4
|
-
import { ApplicationServerApplications } from './applications.js';
|
|
5
|
-
import { DevErrorPolicy } from './error-policy.js';
|
|
6
|
-
import { ApplicationServerJobs } from './jobs.js';
|
|
7
|
-
import { ManagedWorker } from './managed-worker.js';
|
|
8
|
-
import { ApplicationServerProxy } from './proxy.js';
|
|
9
|
-
import { WorkerPool } from './worker-pool.js';
|
|
10
|
-
/**
|
|
11
|
-
* Default factory for creating ManagedWorker instances.
|
|
12
|
-
*/
|
|
13
|
-
export const defaultWorkerFactory = (config, policy, logger) => new ManagedWorker(config, policy, logger);
|
|
14
|
-
/**
|
|
15
|
-
* Default factory for creating WorkerPool instances.
|
|
16
|
-
*/
|
|
17
|
-
export const defaultPoolFactory = (config, policy, workerFactory, logger) => new WorkerPool(config, policy, workerFactory, logger);
|
|
18
|
-
/**
|
|
19
|
-
* ApplicationServer is the main server orchestrator.
|
|
20
|
-
*
|
|
21
|
-
* It manages:
|
|
22
|
-
* - Application worker pools
|
|
23
|
-
* - Job runner pools
|
|
24
|
-
* - Reverse proxy
|
|
25
|
-
* - Store connections
|
|
26
|
-
*
|
|
27
|
-
* The server integrates with ErrorPolicy for proper error handling
|
|
28
|
-
* and uses ManagedWorker for worker lifecycle management.
|
|
29
|
-
*/
|
|
30
|
-
export class ApplicationServer {
|
|
31
|
-
config;
|
|
32
|
-
applicationsConfig;
|
|
33
|
-
workerConfig;
|
|
34
|
-
runOptions;
|
|
35
|
-
errorPolicy;
|
|
36
|
-
workerFactory;
|
|
37
|
-
poolFactory;
|
|
38
|
-
logger;
|
|
39
|
-
applications;
|
|
40
|
-
jobRunners;
|
|
41
|
-
proxy;
|
|
42
|
-
store;
|
|
43
|
-
metrics;
|
|
44
|
-
constructor(config, applicationsConfig, workerConfig, runOptions = {
|
|
45
|
-
applications: Object.keys(config.applications),
|
|
46
|
-
scheduler: false,
|
|
47
|
-
jobs: Boolean(config.jobs?.jobs.size),
|
|
48
|
-
}, errorPolicy = DevErrorPolicy, workerFactory = defaultWorkerFactory, poolFactory = defaultPoolFactory) {
|
|
49
|
-
this.config = config;
|
|
50
|
-
this.applicationsConfig = applicationsConfig;
|
|
51
|
-
this.workerConfig = workerConfig;
|
|
52
|
-
this.runOptions = runOptions;
|
|
53
|
-
this.errorPolicy = errorPolicy;
|
|
54
|
-
this.workerFactory = workerFactory;
|
|
55
|
-
this.poolFactory = poolFactory;
|
|
56
|
-
this.logger = createLogger(config.logger, 'Server');
|
|
57
|
-
this.logger.trace({ applications: applicationsConfig, workerConfig, runOptions }, 'ApplicationServer initialized');
|
|
58
|
-
}
|
|
59
|
-
async start() {
|
|
60
|
-
const { config, logger, errorPolicy, workerFactory, poolFactory } = this;
|
|
61
|
-
logger.info('Starting application server...');
|
|
62
|
-
if (config.metrics) {
|
|
63
|
-
logger.info('Starting metrics server...');
|
|
64
|
-
this.metrics = await createMetricsServer(this.logger, config.metrics);
|
|
65
|
-
await this.metrics.start();
|
|
66
|
-
logger.debug('Metrics server started');
|
|
67
|
-
}
|
|
68
|
-
if (config.store) {
|
|
69
|
-
logger.info('Connecting to store...');
|
|
70
|
-
this.store = await createStoreClient(config.store);
|
|
71
|
-
await this.store.connect();
|
|
72
|
-
logger.debug('Store connected');
|
|
73
|
-
}
|
|
74
|
-
this.applications = new ApplicationServerApplications({
|
|
75
|
-
logger: this.logger,
|
|
76
|
-
workerConfig: this.workerConfig,
|
|
77
|
-
serverConfig: this.config,
|
|
78
|
-
applicationsConfig: this.applicationsConfig,
|
|
79
|
-
applications: this.runOptions.applications,
|
|
80
|
-
errorPolicy,
|
|
81
|
-
workerFactory,
|
|
82
|
-
poolFactory,
|
|
83
|
-
});
|
|
84
|
-
if (this.runOptions.jobs) {
|
|
85
|
-
if (!this.store) {
|
|
86
|
-
throw new Error('Jobs feature requires a store configuration. ' +
|
|
87
|
-
'Please configure `store` in your server config or disable jobs.');
|
|
88
|
-
}
|
|
89
|
-
this.jobRunners = new ApplicationServerJobs({
|
|
90
|
-
logger: this.logger,
|
|
91
|
-
workerConfig: this.workerConfig,
|
|
92
|
-
serverConfig: this.config,
|
|
93
|
-
store: this.store,
|
|
94
|
-
errorPolicy,
|
|
95
|
-
workerFactory,
|
|
96
|
-
poolFactory,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (this.config.proxy) {
|
|
100
|
-
this.logger.debug('Proxy configuration detected, creating a proxy server...');
|
|
101
|
-
this.proxy = new ApplicationServerProxy({
|
|
102
|
-
logger: this.logger,
|
|
103
|
-
config: this.config.proxy,
|
|
104
|
-
applications: this.applications,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
await this.applications.start();
|
|
108
|
-
if (this.runOptions.jobs) {
|
|
109
|
-
await this.jobRunners?.start();
|
|
110
|
-
}
|
|
111
|
-
if (this.runOptions.scheduler && config.jobs?.scheduler) {
|
|
112
|
-
throw new Error('JobsScheduler is currently a work in progress and not available. ' +
|
|
113
|
-
'Scheduled jobs will be supported in a future release.');
|
|
114
|
-
}
|
|
115
|
-
if (this.proxy) {
|
|
116
|
-
logger.info('Starting proxy server...');
|
|
117
|
-
await this.proxy.start();
|
|
118
|
-
logger.debug('Proxy server started');
|
|
119
|
-
}
|
|
120
|
-
logger.info('Application server started');
|
|
121
|
-
}
|
|
122
|
-
async stop() {
|
|
123
|
-
this.logger.info('Stopping application server...');
|
|
124
|
-
// Stop proxy + stop accepting new jobs first
|
|
125
|
-
if (this.proxy) {
|
|
126
|
-
this.logger.info('Stopping proxy server...');
|
|
127
|
-
await this.proxy.stop();
|
|
128
|
-
this.logger.debug('Proxy server stopped');
|
|
129
|
-
}
|
|
130
|
-
if (this.jobRunners) {
|
|
131
|
-
this.logger.info('Stopping job runners...');
|
|
132
|
-
await this.jobRunners.stop();
|
|
133
|
-
this.logger.debug('Job runners stopped');
|
|
134
|
-
}
|
|
135
|
-
// Stop applications
|
|
136
|
-
if (this.applications) {
|
|
137
|
-
this.logger.info('Stopping applications...');
|
|
138
|
-
await this.applications.stop();
|
|
139
|
-
this.logger.debug('Applications stopped');
|
|
140
|
-
}
|
|
141
|
-
// Close store connection
|
|
142
|
-
if (this.store) {
|
|
143
|
-
this.logger.info('Closing store...');
|
|
144
|
-
this.store.disconnect(false);
|
|
145
|
-
this.logger.debug('Store disconnected');
|
|
146
|
-
}
|
|
147
|
-
if (this.metrics) {
|
|
148
|
-
this.logger.info('Stopping metrics server...');
|
|
149
|
-
await this.metrics.stop();
|
|
150
|
-
this.logger.debug('Metrics server stopped');
|
|
151
|
-
}
|
|
152
|
-
this.logger.info('Application server gracefully stopped');
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Restart failed workers across all pools.
|
|
156
|
-
* Called when HMR update comes in and workers may have failed.
|
|
157
|
-
* @returns Number of workers that were restarted
|
|
158
|
-
*/
|
|
159
|
-
async restartFailedWorkers() {
|
|
160
|
-
return (await this.applications?.restartFailedWorkers()) ?? 0;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
//# sourceMappingURL=server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/runtime/server/server.ts"],"names":[],"mapp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,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;QAC3C,CAAC;QAED,yBAAyB;QACzB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;YACpC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAA;QACzC,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;YAC9C,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;YACzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;QAC7C,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;IAC3D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,oBAAoB;QACxB,OAAO,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE,oBAAoB,EAAE,CAAC,IAAI,CAAC,CAAA;IAC/D,CAAC;CACF"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type EventEmitter from 'node:events';
|
|
2
|
-
import type { MessagePort, Worker } from 'node:worker_threads';
|
|
3
|
-
/**
|
|
4
|
-
* Run options for the ApplicationServer.
|
|
5
|
-
*/
|
|
6
|
-
export type ApplicationServerRunOptions = {
|
|
7
|
-
applications: string[];
|
|
8
|
-
scheduler: boolean;
|
|
9
|
-
jobs: boolean;
|
|
10
|
-
};
|
|
11
|
-
export type WorkerRegistration = {
|
|
12
|
-
worker: Worker;
|
|
13
|
-
vitePort?: MessagePort;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Minimal event map required for worker management.
|
|
17
|
-
* The events emitter may have additional events (like 'hmr-update').
|
|
18
|
-
*/
|
|
19
|
-
export type WorkerEventMap = {
|
|
20
|
-
worker: [registration: WorkerRegistration];
|
|
21
|
-
[key: string]: any[];
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Configuration for worker management in ApplicationServer.
|
|
25
|
-
*/
|
|
26
|
-
export type ApplicationServerWorkerConfig = {
|
|
27
|
-
path: string;
|
|
28
|
-
workerData?: any;
|
|
29
|
-
worker?: (registration: WorkerRegistration) => any;
|
|
30
|
-
events?: EventEmitter<WorkerEventMap>;
|
|
31
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/runtime/server/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
import type { Logger } from '@nmtjs/core';
|
|
3
|
-
import type { WorkerType } from '../enums.ts';
|
|
4
|
-
import type { JobTaskResult, WorkerJobTask } from '../types.ts';
|
|
5
|
-
import type { ErrorPolicy } from './error-policy.ts';
|
|
6
|
-
import type { ManagedWorker, ManagedWorkerConfig, WorkerState } from './managed-worker.ts';
|
|
7
|
-
import type { WorkerRegistration } from './types.ts';
|
|
8
|
-
/**
|
|
9
|
-
* Health states for a worker pool.
|
|
10
|
-
*/
|
|
11
|
-
export type PoolHealth = 'healthy' | 'degraded' | 'unhealthy';
|
|
12
|
-
/**
|
|
13
|
-
* Report on pool health status.
|
|
14
|
-
*/
|
|
15
|
-
export interface PoolHealthReport {
|
|
16
|
-
poolName: string;
|
|
17
|
-
overall: PoolHealth;
|
|
18
|
-
healthy: number;
|
|
19
|
-
total: number;
|
|
20
|
-
workers: Array<{
|
|
21
|
-
id: string;
|
|
22
|
-
state: WorkerState;
|
|
23
|
-
consecutiveFailures: number;
|
|
24
|
-
totalFailures: number;
|
|
25
|
-
}>;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Configuration for creating a worker pool.
|
|
29
|
-
*/
|
|
30
|
-
export interface WorkerPoolConfig {
|
|
31
|
-
name: string;
|
|
32
|
-
workerType: WorkerType;
|
|
33
|
-
path: string;
|
|
34
|
-
workerData?: any;
|
|
35
|
-
onWorker?: (registration: WorkerRegistration) => void;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Events emitted by WorkerPool.
|
|
39
|
-
*/
|
|
40
|
-
export interface WorkerPoolEvents {
|
|
41
|
-
'health-change': [health: PoolHealth];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Factory function for creating ManagedWorker instances.
|
|
45
|
-
* This allows for dependency injection and testing.
|
|
46
|
-
*/
|
|
47
|
-
export type ManagedWorkerFactory = (config: ManagedWorkerConfig, policy: ErrorPolicy, logger: Logger) => ManagedWorker;
|
|
48
|
-
/**
|
|
49
|
-
* Factory function for creating WorkerPool instances.
|
|
50
|
-
* This allows for dependency injection and testing.
|
|
51
|
-
*/
|
|
52
|
-
export type WorkerPoolFactory = (config: WorkerPoolConfig, policy: ErrorPolicy, workerFactory: ManagedWorkerFactory, logger: Logger) => WorkerPool;
|
|
53
|
-
/**
|
|
54
|
-
* WorkerPool manages a collection of workers for a single application or job pool.
|
|
55
|
-
*
|
|
56
|
-
* Features:
|
|
57
|
-
* - Health tracking with three states: healthy, degraded, unhealthy
|
|
58
|
-
* - Integration with ErrorPolicy for degraded mode decisions
|
|
59
|
-
* - Worker lifecycle management (start, stop)
|
|
60
|
-
* - Health reports for debugging and monitoring
|
|
61
|
-
*
|
|
62
|
-
* Each application gets its own WorkerPool for isolated failure domains.
|
|
63
|
-
*/
|
|
64
|
-
export declare class WorkerPool extends EventEmitter<WorkerPoolEvents> {
|
|
65
|
-
readonly config: WorkerPoolConfig;
|
|
66
|
-
private readonly policy;
|
|
67
|
-
private readonly workerFactory;
|
|
68
|
-
private workers;
|
|
69
|
-
private health;
|
|
70
|
-
private logger;
|
|
71
|
-
constructor(config: WorkerPoolConfig, policy: ErrorPolicy, workerFactory: ManagedWorkerFactory, logger: Logger);
|
|
72
|
-
/** Current pool health */
|
|
73
|
-
get currentHealth(): PoolHealth;
|
|
74
|
-
/** Total number of workers in the pool */
|
|
75
|
-
get workerCount(): number;
|
|
76
|
-
/** Number of healthy (ready) workers */
|
|
77
|
-
get healthyCount(): number;
|
|
78
|
-
/** Get all workers in this pool */
|
|
79
|
-
getWorkers(): readonly ManagedWorker[];
|
|
80
|
-
/**
|
|
81
|
-
* Add a worker to the pool.
|
|
82
|
-
*
|
|
83
|
-
* @param workerData - Additional data to pass to the worker
|
|
84
|
-
* @param index - Worker index (used for naming)
|
|
85
|
-
* @returns The created ManagedWorker
|
|
86
|
-
*/
|
|
87
|
-
add(workerData: any, index: number): ManagedWorker;
|
|
88
|
-
/**
|
|
89
|
-
* Start all workers in the pool.
|
|
90
|
-
*/
|
|
91
|
-
startAll(): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Restart workers that are in error state.
|
|
94
|
-
* Called when HMR update comes in and there are failed workers.
|
|
95
|
-
* @returns Number of workers that were restarted
|
|
96
|
-
*/
|
|
97
|
-
restartFailedWorkers(): Promise<number>;
|
|
98
|
-
/**
|
|
99
|
-
* Stop all workers in the pool and clean up.
|
|
100
|
-
*/
|
|
101
|
-
stopAll(): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* Get a health report for this pool.
|
|
104
|
-
*/
|
|
105
|
-
getHealthReport(): PoolHealthReport;
|
|
106
|
-
/**
|
|
107
|
-
* Update pool health based on worker states.
|
|
108
|
-
*/
|
|
109
|
-
private updateHealth;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* JobRunnersPool extends WorkerPool with round-robin task execution.
|
|
113
|
-
* Used for job worker pools where tasks need to be distributed across workers.
|
|
114
|
-
*/
|
|
115
|
-
export declare class JobRunnersPool extends WorkerPool {
|
|
116
|
-
private runIndex;
|
|
117
|
-
/**
|
|
118
|
-
* Run a task on the next available worker (round-robin).
|
|
119
|
-
*/
|
|
120
|
-
run(task: WorkerJobTask): Promise<JobTaskResult>;
|
|
121
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
/**
|
|
3
|
-
* WorkerPool manages a collection of workers for a single application or job pool.
|
|
4
|
-
*
|
|
5
|
-
* Features:
|
|
6
|
-
* - Health tracking with three states: healthy, degraded, unhealthy
|
|
7
|
-
* - Integration with ErrorPolicy for degraded mode decisions
|
|
8
|
-
* - Worker lifecycle management (start, stop)
|
|
9
|
-
* - Health reports for debugging and monitoring
|
|
10
|
-
*
|
|
11
|
-
* Each application gets its own WorkerPool for isolated failure domains.
|
|
12
|
-
*/
|
|
13
|
-
export class WorkerPool extends EventEmitter {
|
|
14
|
-
config;
|
|
15
|
-
policy;
|
|
16
|
-
workerFactory;
|
|
17
|
-
workers = [];
|
|
18
|
-
health = 'healthy';
|
|
19
|
-
logger;
|
|
20
|
-
constructor(config, policy, workerFactory, logger) {
|
|
21
|
-
super();
|
|
22
|
-
this.config = config;
|
|
23
|
-
this.policy = policy;
|
|
24
|
-
this.workerFactory = workerFactory;
|
|
25
|
-
this.logger = logger.child({ component: 'WorkerPool', pool: config.name });
|
|
26
|
-
}
|
|
27
|
-
/** Current pool health */
|
|
28
|
-
get currentHealth() {
|
|
29
|
-
return this.health;
|
|
30
|
-
}
|
|
31
|
-
/** Total number of workers in the pool */
|
|
32
|
-
get workerCount() {
|
|
33
|
-
return this.workers.length;
|
|
34
|
-
}
|
|
35
|
-
/** Number of healthy (ready) workers */
|
|
36
|
-
get healthyCount() {
|
|
37
|
-
return this.workers.filter((w) => w.isHealthy).length;
|
|
38
|
-
}
|
|
39
|
-
/** Get all workers in this pool */
|
|
40
|
-
getWorkers() {
|
|
41
|
-
return this.workers;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Add a worker to the pool.
|
|
45
|
-
*
|
|
46
|
-
* @param workerData - Additional data to pass to the worker
|
|
47
|
-
* @param index - Worker index (used for naming)
|
|
48
|
-
* @returns The created ManagedWorker
|
|
49
|
-
*/
|
|
50
|
-
add(workerData, index) {
|
|
51
|
-
const { config } = this;
|
|
52
|
-
const workerConfig = {
|
|
53
|
-
id: `${config.name}-${index + 1}`,
|
|
54
|
-
name: config.name,
|
|
55
|
-
index,
|
|
56
|
-
workerType: config.workerType,
|
|
57
|
-
path: config.path,
|
|
58
|
-
workerData: { ...config.workerData, ...workerData },
|
|
59
|
-
onWorker: config.onWorker,
|
|
60
|
-
};
|
|
61
|
-
const worker = this.workerFactory(workerConfig, this.policy, this.logger);
|
|
62
|
-
worker.on('state-change', () => this.updateHealth());
|
|
63
|
-
this.workers.push(worker);
|
|
64
|
-
return worker;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Start all workers in the pool.
|
|
68
|
-
*/
|
|
69
|
-
async startAll() {
|
|
70
|
-
this.logger.debug({ count: this.workers.length }, 'Starting all workers');
|
|
71
|
-
await Promise.all(this.workers.map((w) => w.start()));
|
|
72
|
-
this.logger.debug({ count: this.workers.length }, 'All workers started');
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Restart workers that are in error state.
|
|
76
|
-
* Called when HMR update comes in and there are failed workers.
|
|
77
|
-
* @returns Number of workers that were restarted
|
|
78
|
-
*/
|
|
79
|
-
async restartFailedWorkers() {
|
|
80
|
-
const failedWorkers = this.workers.filter((w) => w.currentState === 'error');
|
|
81
|
-
if (failedWorkers.length === 0)
|
|
82
|
-
return 0;
|
|
83
|
-
this.logger.debug({ count: failedWorkers.length }, 'Restarting failed workers after HMR update');
|
|
84
|
-
// Reset failure counts before restarting
|
|
85
|
-
for (const worker of failedWorkers) {
|
|
86
|
-
worker.resetFailureCount();
|
|
87
|
-
}
|
|
88
|
-
await Promise.all(failedWorkers.map((w) => w.start()));
|
|
89
|
-
return failedWorkers.length;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Stop all workers in the pool and clean up.
|
|
93
|
-
*/
|
|
94
|
-
async stopAll() {
|
|
95
|
-
this.logger.debug({ count: this.workers.length }, 'Stopping all workers');
|
|
96
|
-
// Remove all event listeners from workers before stopping
|
|
97
|
-
for (const worker of this.workers) {
|
|
98
|
-
worker.removeAllListeners();
|
|
99
|
-
}
|
|
100
|
-
await Promise.all(this.workers.map((w) => w.stop()));
|
|
101
|
-
// Clear workers array
|
|
102
|
-
this.workers = [];
|
|
103
|
-
// Remove all listeners from the pool itself
|
|
104
|
-
this.removeAllListeners();
|
|
105
|
-
this.logger.debug('All workers stopped and cleaned up');
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get a health report for this pool.
|
|
109
|
-
*/
|
|
110
|
-
getHealthReport() {
|
|
111
|
-
return {
|
|
112
|
-
poolName: this.config.name,
|
|
113
|
-
overall: this.health,
|
|
114
|
-
healthy: this.healthyCount,
|
|
115
|
-
total: this.workerCount,
|
|
116
|
-
workers: this.workers.map((w) => ({
|
|
117
|
-
id: w.config.id,
|
|
118
|
-
state: w.currentState,
|
|
119
|
-
consecutiveFailures: w.context.consecutiveFailures,
|
|
120
|
-
totalFailures: w.context.totalFailures,
|
|
121
|
-
})),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Update pool health based on worker states.
|
|
126
|
-
*/
|
|
127
|
-
updateHealth() {
|
|
128
|
-
const readyCount = this.healthyCount;
|
|
129
|
-
const total = this.workerCount;
|
|
130
|
-
let newHealth;
|
|
131
|
-
if (readyCount === total) {
|
|
132
|
-
newHealth = 'healthy';
|
|
133
|
-
}
|
|
134
|
-
else if (readyCount > 0 && this.policy.allowDegradedMode) {
|
|
135
|
-
newHealth = 'degraded';
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
newHealth = 'unhealthy';
|
|
139
|
-
}
|
|
140
|
-
if (newHealth !== this.health) {
|
|
141
|
-
const oldHealth = this.health;
|
|
142
|
-
this.health = newHealth;
|
|
143
|
-
this.logger.trace({ from: oldHealth, to: newHealth, ready: readyCount, total }, 'Pool health changed');
|
|
144
|
-
this.emit('health-change', newHealth);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* JobRunnersPool extends WorkerPool with round-robin task execution.
|
|
150
|
-
* Used for job worker pools where tasks need to be distributed across workers.
|
|
151
|
-
*/
|
|
152
|
-
export class JobRunnersPool extends WorkerPool {
|
|
153
|
-
runIndex = 0;
|
|
154
|
-
/**
|
|
155
|
-
* Run a task on the next available worker (round-robin).
|
|
156
|
-
*/
|
|
157
|
-
async run(task) {
|
|
158
|
-
const workers = this.getWorkers();
|
|
159
|
-
const healthyWorkers = workers.filter((w) => w.isHealthy);
|
|
160
|
-
if (healthyWorkers.length === 0) {
|
|
161
|
-
throw new Error('No healthy job runner threads available');
|
|
162
|
-
}
|
|
163
|
-
if (this.runIndex >= healthyWorkers.length) {
|
|
164
|
-
this.runIndex = 0;
|
|
165
|
-
}
|
|
166
|
-
const worker = healthyWorkers[this.runIndex];
|
|
167
|
-
this.runIndex++;
|
|
168
|
-
return await worker.run(task);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
//# sourceMappingURL=worker-pool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-pool.js","sourceRoot":"","sources":["../../../src/runtime/server/worker-pool.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAA;AA0EtC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,UAAW,SAAQ,YAA8B;IAMjD,MAAM;IACE,MAAM;IACN,aAAa;IAPxB,OAAO,GAAoB,EAAE,CAAA;IAC7B,MAAM,GAAe,SAAS,CAAA;IAC9B,MAAM,CAAQ;IAEtB,YACW,MAAwB,EAChB,MAAmB,EACnB,aAAmC,EACpD,MAAc;QAEd,KAAK,EAAE,CAAA;sBALE,MAAM;sBACE,MAAM;6BACN,aAAa;QAI9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CA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