nmtjs 0.16.1 → 0.17.0-beta.1
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,53 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http';
|
|
2
|
-
import { Pushgateway } from '@nmtjs/prom-client';
|
|
3
|
-
export async function createMetricsServer(logger, config) {
|
|
4
|
-
const { workerRegistry: registry } = await import('./registry.js');
|
|
5
|
-
const { host = '0.0.0.0', port = 9187, path = '/metrics', push } = config;
|
|
6
|
-
let intervalRef;
|
|
7
|
-
if (push) {
|
|
8
|
-
const { url = 'http://127.0.0.1:9091', interval, name: jobName } = push;
|
|
9
|
-
const gateway = new Pushgateway(url, {}, registry);
|
|
10
|
-
intervalRef = setInterval(() => {
|
|
11
|
-
gateway
|
|
12
|
-
.pushAdd({ jobName })
|
|
13
|
-
.catch((cause) => logger.error(new Error('Metrics push error', { cause })));
|
|
14
|
-
}, interval);
|
|
15
|
-
}
|
|
16
|
-
const server = createServer((req, res) => {
|
|
17
|
-
const url = new URL(`http://${req.headers.host || 'localhost'}${req.url}`);
|
|
18
|
-
if (url.pathname === path) {
|
|
19
|
-
res.setHeader('Content-Type', registry.contentType);
|
|
20
|
-
registry
|
|
21
|
-
.workerMetrics()
|
|
22
|
-
.then((metrics) => {
|
|
23
|
-
res.writeHead(200);
|
|
24
|
-
res.end(metrics);
|
|
25
|
-
})
|
|
26
|
-
.catch((cause) => {
|
|
27
|
-
logger.error(new Error('Metrics collection error', { cause }));
|
|
28
|
-
res.writeHead(500);
|
|
29
|
-
res.end('Internal Server Error');
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
res.writeHead(404);
|
|
34
|
-
res.end('Not Found');
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
start: () => new Promise((resolve) => server.listen({ host: host, port: port }, resolve)),
|
|
39
|
-
stop: () => new Promise((resolve, reject) => {
|
|
40
|
-
if (intervalRef)
|
|
41
|
-
clearInterval(intervalRef);
|
|
42
|
-
server.close((err) => {
|
|
43
|
-
if (err) {
|
|
44
|
-
reject(err);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
resolve();
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/runtime/metrics/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAGxC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAIhD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAc,EACd,MAAmD;IAEnD,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAA;IAClE,MAAM,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI,GAAG,UAAU,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAEzE,IAAI,WAAgB,CAAA;IAEpB,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,EAAE,GAAG,GAAG,uBAAuB,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QACvE,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,GAAG,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;QAClD,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE;YAC7B,OAAO;iBACJ,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;iBACpB,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACf,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CACzD,CAAA;QACL,CAAC,EAAE,QAAQ,CAAC,CAAA;IACd,CAAC;IAED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IAAI,WAAW;gBAAE,aAAa,CAAC,WAAW,CAAC,CAAA;YAC3C,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACnB,IAAI,GAAG,EAAE,CAAC;oBACR,MAAM,CAAC,GAAG,CAAC,CAAA;gBACb,CAAC;qBAAM,CAAC;oBACN,OAAO,EAAE,CAAA;gBACX,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC;KACL,CAAA;AACH,CAAC"}
|
package/dist/runtime/plugin.d.ts
DELETED
package/dist/runtime/plugin.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/runtime/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { RuntimePlugin } from '@nmtjs/application';
|
|
2
|
-
import type { Dependant, Logger, LoggingOptions } from '@nmtjs/core';
|
|
3
|
-
import { LifecycleHooks } from '@nmtjs/application';
|
|
4
|
-
import { Container } from '@nmtjs/core';
|
|
5
|
-
export type BaseRuntimeOptions = {
|
|
6
|
-
logger?: LoggingOptions;
|
|
7
|
-
container?: Container;
|
|
8
|
-
plugins?: RuntimePlugin[];
|
|
9
|
-
name?: string;
|
|
10
|
-
};
|
|
11
|
-
export declare abstract class BaseRuntime {
|
|
12
|
-
logger: Logger;
|
|
13
|
-
container: Container;
|
|
14
|
-
lifecycleHooks: LifecycleHooks;
|
|
15
|
-
plugins: RuntimePlugin[];
|
|
16
|
-
constructor(options?: BaseRuntimeOptions);
|
|
17
|
-
protected abstract _initialize(): Promise<void>;
|
|
18
|
-
protected abstract _dispose(): Promise<void>;
|
|
19
|
-
protected abstract _dependents(): Generator<Dependant>;
|
|
20
|
-
reload(...args: any[]): Promise<void>;
|
|
21
|
-
initialize(): Promise<void>;
|
|
22
|
-
dispose(): Promise<void>;
|
|
23
|
-
protected _initializePlugins(): Promise<void>;
|
|
24
|
-
protected _disposePlugins(): Promise<void>;
|
|
25
|
-
protected _initializeContainer(): Promise<void>;
|
|
26
|
-
protected _disposeContainer(): Promise<void>;
|
|
27
|
-
}
|
package/dist/runtime/runtime.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { LifecycleHook, LifecycleHooks } from '@nmtjs/application';
|
|
2
|
-
import { Container, createLogger, getDepedencencyInjectable, Scope, } from '@nmtjs/core';
|
|
3
|
-
export class BaseRuntime {
|
|
4
|
-
logger;
|
|
5
|
-
container;
|
|
6
|
-
lifecycleHooks;
|
|
7
|
-
plugins;
|
|
8
|
-
constructor(options = {}) {
|
|
9
|
-
this.logger = createLogger(options.logger, options.name || 'Runtime');
|
|
10
|
-
this.container = options.container
|
|
11
|
-
? options.container.fork(Scope.Global)
|
|
12
|
-
: new Container({ logger: this.logger });
|
|
13
|
-
this.lifecycleHooks = new LifecycleHooks();
|
|
14
|
-
this.plugins = options.plugins || [];
|
|
15
|
-
}
|
|
16
|
-
async reload(...args) {
|
|
17
|
-
await this._dispose();
|
|
18
|
-
await this._initialize();
|
|
19
|
-
}
|
|
20
|
-
async initialize() {
|
|
21
|
-
this.logger.debug('Initializing a runtime...');
|
|
22
|
-
await this._initializePlugins();
|
|
23
|
-
await this._initializeContainer();
|
|
24
|
-
await this.lifecycleHooks.callHook(LifecycleHook.BeforeInitialize, this);
|
|
25
|
-
await this._initialize();
|
|
26
|
-
await this.lifecycleHooks.callHook(LifecycleHook.AfterInitialize, this);
|
|
27
|
-
this.logger.debug('Runtime initialized');
|
|
28
|
-
}
|
|
29
|
-
async dispose() {
|
|
30
|
-
this.logger.debug('Disposing a runtime...');
|
|
31
|
-
await this.lifecycleHooks.callHook(LifecycleHook.BeforeDispose, this);
|
|
32
|
-
await this._dispose();
|
|
33
|
-
await this.lifecycleHooks.callHook(LifecycleHook.AfterDispose, this);
|
|
34
|
-
await this._disposeContainer();
|
|
35
|
-
await this._disposePlugins();
|
|
36
|
-
this.logger.debug('Runtime disposed');
|
|
37
|
-
}
|
|
38
|
-
async _initializePlugins() {
|
|
39
|
-
if (!this.plugins?.length)
|
|
40
|
-
return;
|
|
41
|
-
for (const { name, hooks, injections } of this.plugins) {
|
|
42
|
-
this.logger.debug(`Initializing plugin [${name}]...`);
|
|
43
|
-
if (injections)
|
|
44
|
-
this.container.provide(injections);
|
|
45
|
-
if (hooks)
|
|
46
|
-
this.lifecycleHooks.addHooks(hooks);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async _disposePlugins() {
|
|
50
|
-
if (!this.plugins?.length)
|
|
51
|
-
return;
|
|
52
|
-
for (const { name, hooks, injections } of this.plugins) {
|
|
53
|
-
this.logger.debug(`Disposing plugin [${name}]...`);
|
|
54
|
-
if (hooks)
|
|
55
|
-
this.lifecycleHooks.removeHooks(hooks);
|
|
56
|
-
if (injections) {
|
|
57
|
-
for (const injection of injections) {
|
|
58
|
-
await this.container.disposeInjectableInstances(injection.token);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async _initializeContainer() {
|
|
64
|
-
const dependents = this._dependents();
|
|
65
|
-
const dependencies = new Set();
|
|
66
|
-
for (const dependant of dependents) {
|
|
67
|
-
for (const dependency of Object.values(dependant.dependencies)) {
|
|
68
|
-
dependencies.add(getDepedencencyInjectable(dependency));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
await this.container.initialize(dependencies);
|
|
72
|
-
}
|
|
73
|
-
async _disposeContainer() {
|
|
74
|
-
await this.container.dispose();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=runtime.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,EACL,SAAS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BAAE,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;YACjD,IAAI,UAAU,EAAE,CAAC;gBACf,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;oBACnC,MAAM,IAAI,CAAC,SAAS,CAAC,0BAA0B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;gBAClE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAES,KAAK,CAAC,oBAAoB;QAClC,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;QACrC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAiB,CAAA;QAC7C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC/D,YAAY,CAAC,GAAG,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC,CAAA;YACzD,CAAC;QACH,CAAC;QACD,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;IAC/C,CAAC;IAES,KAAK,CAAC,iBAAiB;QAC/B,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { AnyJob } from '../jobs/job.ts';
|
|
2
|
-
export interface JobsSchedulerEntry<T extends AnyJob = AnyJob> {
|
|
3
|
-
job: T;
|
|
4
|
-
data: T['_']['input'];
|
|
5
|
-
cron: string;
|
|
6
|
-
}
|
|
7
|
-
export type JobsSchedulerOptions = {
|
|
8
|
-
entries: JobsSchedulerEntry[];
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Job scheduler is currently being refactored and is not available.
|
|
12
|
-
* This will throw an error if instantiated.
|
|
13
|
-
*/
|
|
14
|
-
export declare class JobsScheduler {
|
|
15
|
-
constructor();
|
|
16
|
-
initialize(): Promise<void>;
|
|
17
|
-
stop(): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Job scheduler is currently being refactored and is not available.
|
|
21
|
-
*/
|
|
22
|
-
export declare function createSchedulerJobEntry<T extends AnyJob>(job: T, data: T['_']['input'], cron: string): JobsSchedulerEntry<T>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Job scheduler is currently being refactored and is not available.
|
|
3
|
-
* This will throw an error if instantiated.
|
|
4
|
-
*/
|
|
5
|
-
export class JobsScheduler {
|
|
6
|
-
constructor() {
|
|
7
|
-
throw new Error('JobsScheduler is currently a work in progress and not available. ' +
|
|
8
|
-
'Scheduled jobs will be supported in a future release.');
|
|
9
|
-
}
|
|
10
|
-
async initialize() { }
|
|
11
|
-
async stop() { }
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Job scheduler is currently being refactored and is not available.
|
|
15
|
-
*/
|
|
16
|
-
export function createSchedulerJobEntry(job, data, cron) {
|
|
17
|
-
throw new Error('createSchedulerJobEntry is currently a work in progress and not available. ' +
|
|
18
|
-
'Scheduled jobs will be supported in a future release.');
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/scheduler/index.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,OAAO,aAAa;IACxB;QACE,MAAM,IAAI,KAAK,CACb,mEAAmE;YACjE,uDAAuD,CAC1D,CAAA;IACH,CAAC;IAED,KAAK,CAAC,UAAU,KAAI,CAAC;IACrB,KAAK,CAAC,IAAI,KAAI,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,GAAM,EACN,IAAqB,EACrB,IAAY;IAEZ,MAAM,IAAI,KAAK,CACb,6EAA6E;QAC3E,uDAAuD,CAC1D,CAAA;AACH,CAAC"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
import type { Logger } from '@nmtjs/core';
|
|
3
|
-
import type { ProxyableTransportType } from '@nmtjs/gateway';
|
|
4
|
-
import type { ServerConfig } from './config.ts';
|
|
5
|
-
import type { ErrorPolicy } from './error-policy.ts';
|
|
6
|
-
import type { ManagedWorker } from './managed-worker.ts';
|
|
7
|
-
import type { ApplicationServerWorkerConfig } from './types.ts';
|
|
8
|
-
import type { ManagedWorkerFactory, WorkerPool, WorkerPoolFactory } from './worker-pool.ts';
|
|
9
|
-
export type ApplicationProxyUpstream = {
|
|
10
|
-
type: ProxyableTransportType;
|
|
11
|
-
url: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* ApplicationServerApplications manages all application worker pools.
|
|
15
|
-
*
|
|
16
|
-
* Changes from the old Pool-based implementation:
|
|
17
|
-
* - Uses WorkerPool for each application (isolated failure domains)
|
|
18
|
-
* - Uses ManagedWorker for restart logic and state tracking
|
|
19
|
-
* - Integrates with ErrorPolicy for restart decisions
|
|
20
|
-
* - Proper health tracking per application
|
|
21
|
-
*/
|
|
22
|
-
export declare class ApplicationServerApplications extends EventEmitter<{
|
|
23
|
-
add: [application: string, upstream: ApplicationProxyUpstream];
|
|
24
|
-
remove: [application: string, upstream: ApplicationProxyUpstream];
|
|
25
|
-
}> {
|
|
26
|
-
readonly params: {
|
|
27
|
-
logger: Logger;
|
|
28
|
-
applications: string[];
|
|
29
|
-
workerConfig: ApplicationServerWorkerConfig;
|
|
30
|
-
applicationsConfig: Record<string, {
|
|
31
|
-
type: 'neemata' | 'custom';
|
|
32
|
-
specifier: string;
|
|
33
|
-
}>;
|
|
34
|
-
serverConfig: ServerConfig;
|
|
35
|
-
errorPolicy: ErrorPolicy;
|
|
36
|
-
workerFactory: ManagedWorkerFactory;
|
|
37
|
-
poolFactory: WorkerPoolFactory;
|
|
38
|
-
};
|
|
39
|
-
/** Worker pools per application */
|
|
40
|
-
private pools;
|
|
41
|
-
/** Upstreams for proxy routing */
|
|
42
|
-
protected readonly upstreams: Map<string, Map<string, {
|
|
43
|
-
upstream: ApplicationProxyUpstream;
|
|
44
|
-
count: number;
|
|
45
|
-
}>>;
|
|
46
|
-
/** Track upstreams by worker for cleanup */
|
|
47
|
-
protected readonly upstreamsByWorker: WeakMap<ManagedWorker, {
|
|
48
|
-
application: string;
|
|
49
|
-
key: string;
|
|
50
|
-
}[]>;
|
|
51
|
-
constructor(params: {
|
|
52
|
-
logger: Logger;
|
|
53
|
-
applications: string[];
|
|
54
|
-
workerConfig: ApplicationServerWorkerConfig;
|
|
55
|
-
applicationsConfig: Record<string, {
|
|
56
|
-
type: 'neemata' | 'custom';
|
|
57
|
-
specifier: string;
|
|
58
|
-
}>;
|
|
59
|
-
serverConfig: ServerConfig;
|
|
60
|
-
errorPolicy: ErrorPolicy;
|
|
61
|
-
workerFactory: ManagedWorkerFactory;
|
|
62
|
-
poolFactory: WorkerPoolFactory;
|
|
63
|
-
});
|
|
64
|
-
get appsNames(): string[];
|
|
65
|
-
/**
|
|
66
|
-
* Start all application workers.
|
|
67
|
-
*/
|
|
68
|
-
start(): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Stop all application workers.
|
|
71
|
-
*/
|
|
72
|
-
stop(): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
* Restart failed workers across all pools.
|
|
75
|
-
* Called when HMR update comes in and workers may have failed.
|
|
76
|
-
* @returns Number of workers that were restarted
|
|
77
|
-
*/
|
|
78
|
-
restartFailedWorkers(): Promise<number>;
|
|
79
|
-
/**
|
|
80
|
-
* Get pool for an application.
|
|
81
|
-
*/
|
|
82
|
-
getPool(applicationName: string): WorkerPool | undefined;
|
|
83
|
-
/**
|
|
84
|
-
* Add an upstream for proxy routing.
|
|
85
|
-
*/
|
|
86
|
-
protected addUpstream(application: string, key: string, upstream: ApplicationProxyUpstream): void;
|
|
87
|
-
/**
|
|
88
|
-
* Remove upstreams associated with a worker.
|
|
89
|
-
*/
|
|
90
|
-
protected removeWorkerUpstreams(worker: ManagedWorker): void;
|
|
91
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
import { WorkerType } from '../enums.js';
|
|
3
|
-
/**
|
|
4
|
-
* ApplicationServerApplications manages all application worker pools.
|
|
5
|
-
*
|
|
6
|
-
* Changes from the old Pool-based implementation:
|
|
7
|
-
* - Uses WorkerPool for each application (isolated failure domains)
|
|
8
|
-
* - Uses ManagedWorker for restart logic and state tracking
|
|
9
|
-
* - Integrates with ErrorPolicy for restart decisions
|
|
10
|
-
* - Proper health tracking per application
|
|
11
|
-
*/
|
|
12
|
-
export class ApplicationServerApplications extends EventEmitter {
|
|
13
|
-
params;
|
|
14
|
-
/** Worker pools per application */
|
|
15
|
-
pools = new Map();
|
|
16
|
-
/** Upstreams for proxy routing */
|
|
17
|
-
upstreams = new Map();
|
|
18
|
-
/** Track upstreams by worker for cleanup */
|
|
19
|
-
upstreamsByWorker = new WeakMap();
|
|
20
|
-
constructor(params) {
|
|
21
|
-
super();
|
|
22
|
-
this.params = params;
|
|
23
|
-
}
|
|
24
|
-
get appsNames() {
|
|
25
|
-
return this.params.applications;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Start all application workers.
|
|
29
|
-
*/
|
|
30
|
-
async start() {
|
|
31
|
-
const { logger, applications, applicationsConfig, serverConfig, workerConfig, errorPolicy, workerFactory, poolFactory, } = this.params;
|
|
32
|
-
for (const applicationName of applications) {
|
|
33
|
-
const applicationPath = applicationsConfig[applicationName];
|
|
34
|
-
if (!applicationPath) {
|
|
35
|
-
logger.warn(`Application [${applicationName}] not found in applicationsConfig, skipping...`);
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const applicationConfig = serverConfig.applications[applicationName];
|
|
39
|
-
const threadsConfig = Array.isArray(applicationConfig.threads)
|
|
40
|
-
? applicationConfig.threads
|
|
41
|
-
: new Array(applicationConfig.threads).fill(undefined);
|
|
42
|
-
logger.debug(`Spinning [${threadsConfig.length}] workers for [${applicationName}] application...`);
|
|
43
|
-
// Create a WorkerPool for this application
|
|
44
|
-
const poolConfig = {
|
|
45
|
-
name: `application-${applicationName}`,
|
|
46
|
-
workerType: WorkerType.Application,
|
|
47
|
-
path: workerConfig.path,
|
|
48
|
-
workerData: { ...workerConfig.workerData },
|
|
49
|
-
onWorker: workerConfig.worker,
|
|
50
|
-
};
|
|
51
|
-
const pool = poolFactory(poolConfig, errorPolicy, workerFactory, logger);
|
|
52
|
-
// Add workers to the pool
|
|
53
|
-
for (let i = 0; i < threadsConfig.length; i++) {
|
|
54
|
-
if (applicationPath.type !== 'neemata') {
|
|
55
|
-
throw new Error(`Unsupported custom application worker: ${applicationName}`);
|
|
56
|
-
}
|
|
57
|
-
const workerData = {
|
|
58
|
-
runtime: {
|
|
59
|
-
type: 'application',
|
|
60
|
-
name: applicationName,
|
|
61
|
-
path: applicationPath.specifier,
|
|
62
|
-
transportsData: threadsConfig[i],
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
const worker = pool.add(workerData, i);
|
|
66
|
-
// Handle worker ready - update upstreams
|
|
67
|
-
worker.on('ready', (hosts) => {
|
|
68
|
-
this.removeWorkerUpstreams(worker);
|
|
69
|
-
const keys = [];
|
|
70
|
-
const sanitizedHosts = [];
|
|
71
|
-
if (hosts?.length) {
|
|
72
|
-
for (const host of hosts) {
|
|
73
|
-
const url = new URL(host.url);
|
|
74
|
-
if (url.hostname === '0.0.0.0')
|
|
75
|
-
url.hostname = '127.0.0.1';
|
|
76
|
-
const normalizedUrl = url.toString();
|
|
77
|
-
sanitizedHosts.push({ type: host.type, url: normalizedUrl });
|
|
78
|
-
const upstream = {
|
|
79
|
-
type: host.type,
|
|
80
|
-
url: normalizedUrl,
|
|
81
|
-
};
|
|
82
|
-
const key = `${upstream.type}:${upstream.url}`;
|
|
83
|
-
keys.push({ application: applicationName, key });
|
|
84
|
-
this.addUpstream(applicationName, key, upstream);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
this.upstreamsByWorker.set(worker, keys);
|
|
88
|
-
});
|
|
89
|
-
// Handle worker error - clean up upstreams
|
|
90
|
-
worker.on('error', (_error) => {
|
|
91
|
-
this.removeWorkerUpstreams(worker);
|
|
92
|
-
});
|
|
93
|
-
// Handle worker state changes for upstream cleanup
|
|
94
|
-
worker.on('state-change', (from, to) => {
|
|
95
|
-
if (to === 'stopping' || to === 'stopped' || to === 'error') {
|
|
96
|
-
this.removeWorkerUpstreams(worker);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
this.pools.set(applicationName, pool);
|
|
101
|
-
}
|
|
102
|
-
// Start all pools
|
|
103
|
-
await Promise.all([...this.pools.values()].map((p) => p.startAll()));
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Stop all application workers.
|
|
107
|
-
*/
|
|
108
|
-
async stop() {
|
|
109
|
-
await Promise.all([...this.pools.values()].map((p) => p.stopAll()));
|
|
110
|
-
this.pools.clear();
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Restart failed workers across all pools.
|
|
114
|
-
* Called when HMR update comes in and workers may have failed.
|
|
115
|
-
* @returns Number of workers that were restarted
|
|
116
|
-
*/
|
|
117
|
-
async restartFailedWorkers() {
|
|
118
|
-
let total = 0;
|
|
119
|
-
for (const pool of this.pools.values()) {
|
|
120
|
-
total += await pool.restartFailedWorkers();
|
|
121
|
-
}
|
|
122
|
-
return total;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Get pool for an application.
|
|
126
|
-
*/
|
|
127
|
-
getPool(applicationName) {
|
|
128
|
-
return this.pools.get(applicationName);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Add an upstream for proxy routing.
|
|
132
|
-
*/
|
|
133
|
-
addUpstream(application, key, upstream) {
|
|
134
|
-
let appUpstreams = this.upstreams.get(application);
|
|
135
|
-
if (!appUpstreams) {
|
|
136
|
-
appUpstreams = new Map();
|
|
137
|
-
this.upstreams.set(application, appUpstreams);
|
|
138
|
-
}
|
|
139
|
-
const current = appUpstreams.get(key);
|
|
140
|
-
if (!current) {
|
|
141
|
-
appUpstreams.set(key, { upstream, count: 1 });
|
|
142
|
-
this.emit('add', application, upstream);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
current.count++;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Remove upstreams associated with a worker.
|
|
149
|
-
*/
|
|
150
|
-
removeWorkerUpstreams(worker) {
|
|
151
|
-
const keys = this.upstreamsByWorker.get(worker);
|
|
152
|
-
if (!keys)
|
|
153
|
-
return;
|
|
154
|
-
this.upstreamsByWorker.delete(worker);
|
|
155
|
-
for (const { application, key } of keys) {
|
|
156
|
-
const appUpstreams = this.upstreams.get(application);
|
|
157
|
-
const current = appUpstreams?.get(key);
|
|
158
|
-
if (!current)
|
|
159
|
-
continue;
|
|
160
|
-
current.count--;
|
|
161
|
-
if (current.count <= 0) {
|
|
162
|
-
appUpstreams?.delete(key);
|
|
163
|
-
this.emit('remove', application, current.upstream);
|
|
164
|
-
}
|
|
165
|
-
if (appUpstreams && appUpstreams.size === 0) {
|
|
166
|
-
this.upstreams.delete(application);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
//# sourceMappingURL=applications.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"applications.js","sourceRoot":"","sources":["../../../src/runtime/server/applications.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAA;AAgBtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAOxC;;;;;;;;GAQG;AACH,MAAM,OAAO,6BAA8B,SAAQ,YAGjD;IAiBW,MAAM;IAhBjB,mCAAmC;IAC3B,KAAK,GAAG,IAAI,GAAG,E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YAC7C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAA;YACvC,OAAM;QACR,CAAC;QAED,OAAO,CAAC,KAAK,EAAE,CAAA;IACjB,CAAC;IAED;;OAEG;IACO,qBAAqB,CAAC,MAAqB;QACnD,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAC/C,IAAI,CAAC,IAAI;YAAE,OAAM;QACjB,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAErC,KAAK,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC;YACxC,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;YACpD,MAAM,OAAO,GAAG,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;YACtC,IAAI,CAAC,OAAO;gBAAE,SAAQ;YAEtB,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,IAAI,OAAO,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC;gBACvB,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;gBACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;YACpD,CAAC;YACD,IAAI,YAAY,IAAI,YAAY,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBAC5C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YACpC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type { ApplicationHost, ApplicationHostDefinition, TransportOptionsOf } from '@nmtjs/application';
|
|
2
|
-
import type { LoggingOptions } from '@nmtjs/core';
|
|
3
|
-
import type { ApplicationOptions } from '@nmtjs/proxy';
|
|
4
|
-
import type { Applications } from 'nmtjs/runtime/types';
|
|
5
|
-
import type { StoreType } from '../enums.ts';
|
|
6
|
-
import type { AnyJob } from '../jobs/job.ts';
|
|
7
|
-
import type { JobsSchedulerOptions } from '../scheduler/index.ts';
|
|
8
|
-
import type { SubscriptionAdapterType } from '../subscription/manager.ts';
|
|
9
|
-
import type { StoreTypeOptions } from '../types.ts';
|
|
10
|
-
import { kServerConfig } from '../constants.ts';
|
|
11
|
-
export type ServerPoolOptions = {
|
|
12
|
-
/**
|
|
13
|
-
* Number of worker threads
|
|
14
|
-
*/
|
|
15
|
-
threads: number;
|
|
16
|
-
/**
|
|
17
|
-
* Max number of jobs per worker
|
|
18
|
-
*/
|
|
19
|
-
jobs: number;
|
|
20
|
-
};
|
|
21
|
-
export type ServerStoreConfig = {
|
|
22
|
-
type: StoreType.Redis;
|
|
23
|
-
options: StoreTypeOptions[StoreType.Redis];
|
|
24
|
-
} | {
|
|
25
|
-
type: StoreType.Valkey;
|
|
26
|
-
options: StoreTypeOptions[StoreType.Valkey];
|
|
27
|
-
};
|
|
28
|
-
export type ServerApplicationConfig<T = ApplicationHostDefinition> = T extends ApplicationHostDefinition<any, infer Transports> ? {
|
|
29
|
-
threads: {
|
|
30
|
-
[K in keyof Transports]: TransportOptionsOf<Transports[K]>;
|
|
31
|
-
}[];
|
|
32
|
-
} : T extends ApplicationHost<infer Transports> ? {
|
|
33
|
-
threads: {
|
|
34
|
-
[K in keyof Transports]: TransportOptionsOf<Transports[K]>;
|
|
35
|
-
}[];
|
|
36
|
-
} : any;
|
|
37
|
-
export type ServerJobsConfig = {
|
|
38
|
-
pools: Record<string, ServerPoolOptions>;
|
|
39
|
-
jobs?: AnyJob[];
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Scheduler is currently being refactored and is not available.
|
|
42
|
-
* Using this option will throw an error at startup.
|
|
43
|
-
*/
|
|
44
|
-
scheduler?: JobsSchedulerOptions;
|
|
45
|
-
};
|
|
46
|
-
type ServerApplicationDefinitionConfig<T> = T extends {
|
|
47
|
-
type: 'neemata';
|
|
48
|
-
definition: infer Definition;
|
|
49
|
-
} ? ServerApplicationConfig<Definition> : ServerApplicationConfig<any>;
|
|
50
|
-
export interface ServerConfigInit {
|
|
51
|
-
logger: LoggingOptions;
|
|
52
|
-
applications: {
|
|
53
|
-
[K in keyof Applications]: ServerApplicationDefinitionConfig<Applications[K]>;
|
|
54
|
-
};
|
|
55
|
-
store?: ServerStoreConfig;
|
|
56
|
-
/**
|
|
57
|
-
* Proxy configuration. Enabling this will start a reverse proxy server that handles TLS, routing,
|
|
58
|
-
* load balancing, and health checks for your applications.
|
|
59
|
-
*
|
|
60
|
-
* The applications will be accessible via `<hostname>:<port>/<application-name>/**`
|
|
61
|
-
*
|
|
62
|
-
* Requires adding `@nmtjs/proxy` package to your dependencies
|
|
63
|
-
* and [`cargo`](https://doc.rust-lang.org/cargo/getting-started/installation.html) alongside with
|
|
64
|
-
* [`rustc`](https://www.rust-lang.org/tools/install) to be available globally for building native modules.
|
|
65
|
-
*/
|
|
66
|
-
proxy?: {
|
|
67
|
-
port: number;
|
|
68
|
-
hostname: string;
|
|
69
|
-
applications: {
|
|
70
|
-
[K in keyof Applications]?: Omit<ApplicationOptions, 'name'>;
|
|
71
|
-
};
|
|
72
|
-
threads?: number;
|
|
73
|
-
healthChecks?: {
|
|
74
|
-
interval?: number;
|
|
75
|
-
};
|
|
76
|
-
tls?: {
|
|
77
|
-
key: string;
|
|
78
|
-
cert: string;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
jobs?: ServerJobsConfig;
|
|
82
|
-
commands?: {};
|
|
83
|
-
subscription?: {
|
|
84
|
-
adapter: SubscriptionAdapterType;
|
|
85
|
-
};
|
|
86
|
-
deploymentId?: string;
|
|
87
|
-
metrics?: {
|
|
88
|
-
/**
|
|
89
|
-
* @default '/metrics'
|
|
90
|
-
*/
|
|
91
|
-
path?: string;
|
|
92
|
-
/**
|
|
93
|
-
* @default 9187
|
|
94
|
-
*/
|
|
95
|
-
port?: number;
|
|
96
|
-
/**
|
|
97
|
-
* @default 0.0.0.0
|
|
98
|
-
*/
|
|
99
|
-
host?: string;
|
|
100
|
-
push?: {
|
|
101
|
-
/**
|
|
102
|
-
* Pushgateway URL (including protocol and port)
|
|
103
|
-
*
|
|
104
|
-
* @default http://127.0.0.1:9091
|
|
105
|
-
*/
|
|
106
|
-
url?: string;
|
|
107
|
-
/**
|
|
108
|
-
* Job name for the pushgateway
|
|
109
|
-
*/
|
|
110
|
-
name: string;
|
|
111
|
-
/**
|
|
112
|
-
* Push interval in milliseconds
|
|
113
|
-
*/
|
|
114
|
-
interval: number;
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
export interface ServerConfig {
|
|
119
|
-
[kServerConfig]: true;
|
|
120
|
-
logger: ServerConfigInit['logger'];
|
|
121
|
-
applications: ServerConfigInit['applications'];
|
|
122
|
-
store: ServerConfigInit['store'];
|
|
123
|
-
/**
|
|
124
|
-
* Proxy configuration. Enabling this will start a reverse proxy server that handles TLS, routing,
|
|
125
|
-
* load balancing, and health checks for your applications.
|
|
126
|
-
*
|
|
127
|
-
* The applications will be accessible via `<hostname>:<port>/<application-name>/**`
|
|
128
|
-
*
|
|
129
|
-
* Requires adding `@nmtjs/proxy` package to your dependencies
|
|
130
|
-
*/
|
|
131
|
-
proxy: ServerConfigInit['proxy'];
|
|
132
|
-
jobs?: {
|
|
133
|
-
pools: ServerJobsConfig['pools'];
|
|
134
|
-
jobs: Map<string, AnyJob>;
|
|
135
|
-
/**
|
|
136
|
-
* @deprecated Scheduler is currently being refactored and is not available.
|
|
137
|
-
* Using this option will throw an error at startup.
|
|
138
|
-
*/
|
|
139
|
-
scheduler?: JobsSchedulerOptions;
|
|
140
|
-
};
|
|
141
|
-
commands?: {};
|
|
142
|
-
subscription: ServerConfigInit['subscription'];
|
|
143
|
-
deploymentId: ServerConfigInit['deploymentId'];
|
|
144
|
-
metrics?: ServerConfigInit['metrics'];
|
|
145
|
-
}
|
|
146
|
-
export declare function defineServer(options: ServerConfigInit): ServerConfig;
|
|
147
|
-
export declare function isServerConfig(value: any): value is ServerConfig;
|
|
148
|
-
export {};
|