@omnitron-dev/titan-pm 0.1.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 +21 -0
- package/README.md +27 -0
- package/dist/common-types.d.ts +59 -0
- package/dist/common-types.d.ts.map +1 -0
- package/dist/common-types.js +23 -0
- package/dist/common-types.js.map +1 -0
- package/dist/decorators.d.ts +41 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +372 -0
- package/dist/decorators.js.map +1 -0
- package/dist/fork-worker.d.ts +2 -0
- package/dist/fork-worker.d.ts.map +1 -0
- package/dist/fork-worker.js +66 -0
- package/dist/fork-worker.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/netron-client.d.ts +46 -0
- package/dist/netron-client.d.ts.map +1 -0
- package/dist/netron-client.js +222 -0
- package/dist/netron-client.js.map +1 -0
- package/dist/pm.module.d.ts +23 -0
- package/dist/pm.module.d.ts.map +1 -0
- package/dist/pm.module.js +176 -0
- package/dist/pm.module.js.map +1 -0
- package/dist/process-health.d.ts +37 -0
- package/dist/process-health.d.ts.map +1 -0
- package/dist/process-health.js +245 -0
- package/dist/process-health.js.map +1 -0
- package/dist/process-manager.d.ts +42 -0
- package/dist/process-manager.d.ts.map +1 -0
- package/dist/process-manager.js +435 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/process-metrics.d.ts +22 -0
- package/dist/process-metrics.d.ts.map +1 -0
- package/dist/process-metrics.js +169 -0
- package/dist/process-metrics.js.map +1 -0
- package/dist/process-pool.d.ts +107 -0
- package/dist/process-pool.d.ts.map +1 -0
- package/dist/process-pool.js +1035 -0
- package/dist/process-pool.js.map +1 -0
- package/dist/process-registry.d.ts +14 -0
- package/dist/process-registry.d.ts.map +1 -0
- package/dist/process-registry.js +59 -0
- package/dist/process-registry.js.map +1 -0
- package/dist/process-spawner.d.ts +64 -0
- package/dist/process-spawner.d.ts.map +1 -0
- package/dist/process-spawner.js +596 -0
- package/dist/process-spawner.js.map +1 -0
- package/dist/process-supervisor.d.ts +43 -0
- package/dist/process-supervisor.d.ts.map +1 -0
- package/dist/process-supervisor.js +319 -0
- package/dist/process-supervisor.js.map +1 -0
- package/dist/process-workflow.d.ts +31 -0
- package/dist/process-workflow.d.ts.map +1 -0
- package/dist/process-workflow.js +265 -0
- package/dist/process-workflow.js.map +1 -0
- package/dist/service-proxy.d.ts +29 -0
- package/dist/service-proxy.d.ts.map +1 -0
- package/dist/service-proxy.js +245 -0
- package/dist/service-proxy.js.map +1 -0
- package/dist/types.d.ts +523 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +40 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/deque.d.ts +17 -0
- package/dist/utils/deque.d.ts.map +1 -0
- package/dist/utils/deque.js +86 -0
- package/dist/utils/deque.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/worker-runtime.d.ts +2 -0
- package/dist/worker-runtime.d.ts.map +1 -0
- package/dist/worker-runtime.js +503 -0
- package/dist/worker-runtime.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fork-worker.js","sourceRoot":"","sources":["../src/fork-worker.ts"],"names":[],"mappings":"AAOA,OAAO,kBAAkB,CAAC;AAI1B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,CAAC;AAGrG,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IACxD,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC;QAC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,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE;KACtE,CAAC,CAAC;IACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { ProcessManagerModule, PM_CONFIG_TOKEN, PM_MANAGER_TOKEN, PM_REGISTRY_TOKEN, PM_SPAWNER_TOKEN, PM_METRICS_TOKEN, PM_HEALTH_TOKEN, DEFAULT_PM_CONFIG, } from './pm.module.js';
|
|
2
|
+
export { ProcessManager } from './process-manager.js';
|
|
3
|
+
export { ProcessRegistry } from './process-registry.js';
|
|
4
|
+
export { ProcessSpawner, ProcessSpawnerFactory } from './process-spawner.js';
|
|
5
|
+
export { ProcessPool } from './process-pool.js';
|
|
6
|
+
export { ProcessSupervisor } from './process-supervisor.js';
|
|
7
|
+
export { ProcessMetricsCollector } from './process-metrics.js';
|
|
8
|
+
export { ProcessHealthChecker } from './process-health.js';
|
|
9
|
+
export { Supervisor, Child, CircuitBreaker, RateLimit, Idempotent, PROCESS_METADATA_KEY, PROCESS_METHOD_METADATA_KEY, SUPERVISOR_METADATA_KEY, } from './decorators.js';
|
|
10
|
+
export { ProcessStatus, PoolStrategy, SupervisionStrategy, RestartDecision } from './types.js';
|
|
11
|
+
export type { IProcessOptions, IProcessMetadata, IProcessMethodMetadata, IProcessInfo, ServiceProxy, IServiceProxyControl, IProcessPoolOptions, IProcessPool, ISupervisorOptions, ISupervisorChild, ISupervisorConfig, ISupervisorChildConfig, IProcessEvents, IProcessMetrics, IPoolMetrics, ILatencyMetrics, IHealthStatus, IHealthCheck, IBackoffOptions, IRestartPolicy, IProcessManager, IProcessManagerConfig, IProcessManagerModule, IProcessSpawner, ISpawnOptions, IWorkerHandle, } from './types.js';
|
|
12
|
+
export type { ProcessMethod, AsyncProcessMethod, ServiceMethodMap } from './common-types.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAM3D,OAAO,EAEL,UAAU,EACV,KAAK,EAGL,cAAc,EACd,SAAS,EACT,UAAU,EAGV,oBAAoB,EACpB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAM/F,YAAY,EAEV,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EAGZ,YAAY,EACZ,oBAAoB,EAGpB,mBAAmB,EACnB,YAAY,EAGZ,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EAGtB,cAAc,EAGd,eAAe,EACf,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,EAGZ,eAAe,EACf,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EAGrB,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ProcessManagerModule, PM_CONFIG_TOKEN, PM_MANAGER_TOKEN, PM_REGISTRY_TOKEN, PM_SPAWNER_TOKEN, PM_METRICS_TOKEN, PM_HEALTH_TOKEN, DEFAULT_PM_CONFIG, } from './pm.module.js';
|
|
2
|
+
export { ProcessManager } from './process-manager.js';
|
|
3
|
+
export { ProcessRegistry } from './process-registry.js';
|
|
4
|
+
export { ProcessSpawner, ProcessSpawnerFactory } from './process-spawner.js';
|
|
5
|
+
export { ProcessPool } from './process-pool.js';
|
|
6
|
+
export { ProcessSupervisor } from './process-supervisor.js';
|
|
7
|
+
export { ProcessMetricsCollector } from './process-metrics.js';
|
|
8
|
+
export { ProcessHealthChecker } from './process-health.js';
|
|
9
|
+
export { Supervisor, Child, CircuitBreaker, RateLimit, Idempotent, PROCESS_METADATA_KEY, PROCESS_METHOD_METADATA_KEY, SUPERVISOR_METADATA_KEY, } from './decorators.js';
|
|
10
|
+
export { ProcessStatus, PoolStrategy, SupervisionStrategy, RestartDecision } from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAM3D,OAAO,EAEL,UAAU,EACV,KAAK,EAGL,cAAc,EACd,SAAS,EACT,UAAU,EAGV,oBAAoB,EACpB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Netron } from '@omnitron-dev/titan/netron';
|
|
2
|
+
import type { ILogger } from '@omnitron-dev/titan/module/logger';
|
|
3
|
+
export declare enum ConnectionState {
|
|
4
|
+
DISCONNECTED = "disconnected",
|
|
5
|
+
CONNECTING = "connecting",
|
|
6
|
+
CONNECTED = "connected",
|
|
7
|
+
RECONNECTING = "reconnecting",
|
|
8
|
+
DISCONNECTING = "disconnecting",
|
|
9
|
+
FAILED = "failed"
|
|
10
|
+
}
|
|
11
|
+
export interface INetronClientOptions {
|
|
12
|
+
connectTimeout?: number;
|
|
13
|
+
maxRetries?: number;
|
|
14
|
+
baseDelay?: number;
|
|
15
|
+
maxDelay?: number;
|
|
16
|
+
autoReconnect?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class NetronClient {
|
|
19
|
+
private readonly processId;
|
|
20
|
+
private readonly logger;
|
|
21
|
+
private netron;
|
|
22
|
+
private remotePeer?;
|
|
23
|
+
private _state;
|
|
24
|
+
private options;
|
|
25
|
+
private retryCount;
|
|
26
|
+
private disconnectHandler?;
|
|
27
|
+
private transportUrl?;
|
|
28
|
+
private reconnectTimer?;
|
|
29
|
+
constructor(processId: string, logger: ILogger, options?: INetronClientOptions);
|
|
30
|
+
get state(): ConnectionState;
|
|
31
|
+
start(): Promise<void>;
|
|
32
|
+
connect(transportUrl: string): Promise<void>;
|
|
33
|
+
private connectWithRetry;
|
|
34
|
+
private doConnect;
|
|
35
|
+
private setupDisconnectHandler;
|
|
36
|
+
private scheduleReconnect;
|
|
37
|
+
queryInterface<T>(serviceName: string): Promise<T | null>;
|
|
38
|
+
call(serviceName: string, methodName: string, args: unknown[]): Promise<unknown>;
|
|
39
|
+
disconnect(): Promise<void>;
|
|
40
|
+
private cleanup;
|
|
41
|
+
getNetron(): Netron;
|
|
42
|
+
isConnected(): boolean;
|
|
43
|
+
private createTimeout;
|
|
44
|
+
private sleep;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=netron-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"netron-client.d.ts","sourceRoot":"","sources":["../src/netron-client.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAKjE,oBAAY,eAAe;IACzB,YAAY,iBAAiB;IAC7B,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,YAAY,iBAAiB;IAC7B,aAAa,kBAAkB;IAC/B,MAAM,WAAW;CAClB;AAKD,MAAM,WAAW,oBAAoB;IAInC,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,UAAU,CAAC,EAAE,MAAM,CAAC;IAIpB,SAAS,CAAC,EAAE,MAAM,CAAC;IAInB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAIlB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAaD,qBAAa,YAAY;IAWrB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAXzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAC,CAAa;IAChC,OAAO,CAAC,MAAM,CAAiD;IAC/D,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,iBAAiB,CAAC,CAAa;IACvC,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,cAAc,CAAC,CAAiB;gBAGrB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,EAChC,OAAO,GAAE,oBAAyB;IAYpC,IAAI,KAAK,IAAI,eAAe,CAE3B;IAKK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAWtB,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAyBpC,gBAAgB;YAwChB,SAAS;IAuBvB,OAAO,CAAC,sBAAsB;IA+B9B,OAAO,CAAC,iBAAiB;IAuBnB,cAAc,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IA6BzD,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBhF,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAiCjC,OAAO,CAAC,OAAO;IA0Bf,SAAS,IAAI,MAAM;IAOnB,WAAW,IAAI,OAAO;IAOtB,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Netron } from '@omnitron-dev/titan/netron';
|
|
2
|
+
import { Errors } from '@omnitron-dev/titan/errors';
|
|
3
|
+
export var ConnectionState;
|
|
4
|
+
(function (ConnectionState) {
|
|
5
|
+
ConnectionState["DISCONNECTED"] = "disconnected";
|
|
6
|
+
ConnectionState["CONNECTING"] = "connecting";
|
|
7
|
+
ConnectionState["CONNECTED"] = "connected";
|
|
8
|
+
ConnectionState["RECONNECTING"] = "reconnecting";
|
|
9
|
+
ConnectionState["DISCONNECTING"] = "disconnecting";
|
|
10
|
+
ConnectionState["FAILED"] = "failed";
|
|
11
|
+
})(ConnectionState || (ConnectionState = {}));
|
|
12
|
+
const DEFAULT_OPTIONS = {
|
|
13
|
+
connectTimeout: 10000,
|
|
14
|
+
maxRetries: 3,
|
|
15
|
+
baseDelay: 1000,
|
|
16
|
+
maxDelay: 30000,
|
|
17
|
+
autoReconnect: false,
|
|
18
|
+
};
|
|
19
|
+
export class NetronClient {
|
|
20
|
+
constructor(processId, logger, options = {}) {
|
|
21
|
+
this.processId = processId;
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
this._state = ConnectionState.DISCONNECTED;
|
|
24
|
+
this.retryCount = 0;
|
|
25
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
26
|
+
this.netron = new Netron(logger, {
|
|
27
|
+
id: `pm-client-${processId}`,
|
|
28
|
+
allowServiceEvents: true,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
get state() {
|
|
32
|
+
return this._state;
|
|
33
|
+
}
|
|
34
|
+
async start() {
|
|
35
|
+
const { UnixSocketTransport } = await import('@omnitron-dev/titan/netron/transport/unix');
|
|
36
|
+
this.netron.registerTransport('unix', () => new UnixSocketTransport());
|
|
37
|
+
await this.netron.start();
|
|
38
|
+
}
|
|
39
|
+
async connect(transportUrl) {
|
|
40
|
+
if (this._state === ConnectionState.CONNECTED) {
|
|
41
|
+
this.logger.debug({ processId: this.processId }, 'Already connected');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (this._state === ConnectionState.CONNECTING) {
|
|
45
|
+
throw Errors.conflict('Connection already in progress');
|
|
46
|
+
}
|
|
47
|
+
this._state = ConnectionState.CONNECTING;
|
|
48
|
+
this.transportUrl = transportUrl;
|
|
49
|
+
this.retryCount = 0;
|
|
50
|
+
try {
|
|
51
|
+
await this.connectWithRetry(transportUrl);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this._state = ConnectionState.FAILED;
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async connectWithRetry(transportUrl) {
|
|
59
|
+
while (this.retryCount <= this.options.maxRetries) {
|
|
60
|
+
try {
|
|
61
|
+
await this.doConnect(transportUrl);
|
|
62
|
+
this.retryCount = 0;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
this.retryCount++;
|
|
67
|
+
const isLastAttempt = this.retryCount > this.options.maxRetries;
|
|
68
|
+
this.logger.warn({
|
|
69
|
+
processId: this.processId,
|
|
70
|
+
transportUrl,
|
|
71
|
+
attempt: this.retryCount,
|
|
72
|
+
maxRetries: this.options.maxRetries,
|
|
73
|
+
error: error instanceof Error ? error.message : String(error),
|
|
74
|
+
}, isLastAttempt ? 'Connection failed, no more retries' : 'Connection failed, retrying');
|
|
75
|
+
if (isLastAttempt) {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
const delay = Math.min(this.options.baseDelay * Math.pow(2, this.retryCount - 1) + Math.random() * 1000, this.options.maxDelay);
|
|
79
|
+
await this.sleep(delay);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async doConnect(transportUrl) {
|
|
84
|
+
const peer = await Promise.race([
|
|
85
|
+
this.netron.connect(transportUrl, false),
|
|
86
|
+
this.createTimeout(this.options.connectTimeout, 'Connection'),
|
|
87
|
+
]);
|
|
88
|
+
this.remotePeer = peer;
|
|
89
|
+
this.setupDisconnectHandler();
|
|
90
|
+
this._state = ConnectionState.CONNECTED;
|
|
91
|
+
this.logger.info({ processId: this.processId, transportUrl }, 'Connected to process');
|
|
92
|
+
}
|
|
93
|
+
setupDisconnectHandler() {
|
|
94
|
+
if (!this.remotePeer)
|
|
95
|
+
return;
|
|
96
|
+
const peerAny = this.remotePeer;
|
|
97
|
+
if (this.disconnectHandler && typeof peerAny.off === 'function') {
|
|
98
|
+
peerAny.off('manual-disconnect', this.disconnectHandler);
|
|
99
|
+
}
|
|
100
|
+
this.disconnectHandler = () => {
|
|
101
|
+
this.logger.warn({ processId: this.processId }, 'Remote peer disconnected');
|
|
102
|
+
this._state = ConnectionState.DISCONNECTED;
|
|
103
|
+
this.cleanup();
|
|
104
|
+
if (this.options.autoReconnect && this.transportUrl) {
|
|
105
|
+
this.scheduleReconnect();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
if (typeof peerAny.once === 'function') {
|
|
109
|
+
peerAny.once('manual-disconnect', this.disconnectHandler);
|
|
110
|
+
}
|
|
111
|
+
else if (typeof peerAny.on === 'function') {
|
|
112
|
+
peerAny.on('manual-disconnect', this.disconnectHandler);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
scheduleReconnect() {
|
|
116
|
+
if (this._state === ConnectionState.RECONNECTING)
|
|
117
|
+
return;
|
|
118
|
+
this._state = ConnectionState.RECONNECTING;
|
|
119
|
+
const delay = this.options.baseDelay;
|
|
120
|
+
this.logger.info({ processId: this.processId, delay }, 'Scheduling reconnection');
|
|
121
|
+
this.reconnectTimer = setTimeout(async () => {
|
|
122
|
+
if (this.transportUrl && this._state === ConnectionState.RECONNECTING) {
|
|
123
|
+
try {
|
|
124
|
+
await this.connectWithRetry(this.transportUrl);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
this.logger.error({ error, processId: this.processId }, 'Reconnection failed');
|
|
128
|
+
this._state = ConnectionState.FAILED;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}, delay);
|
|
132
|
+
}
|
|
133
|
+
async queryInterface(serviceName) {
|
|
134
|
+
if (this._state !== ConnectionState.CONNECTED || !this.remotePeer) {
|
|
135
|
+
throw Errors.conflict(`Not connected to process (state: ${this._state})`);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const serviceStub = await this.remotePeer.queryInterface(serviceName);
|
|
139
|
+
return serviceStub;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
this.logger.warn({
|
|
143
|
+
error: error instanceof Error ? error.message : String(error),
|
|
144
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
145
|
+
serviceName,
|
|
146
|
+
processId: this.processId,
|
|
147
|
+
peerConnected: !!this.remotePeer,
|
|
148
|
+
socketReady: this.remotePeer?.socket?.readyState,
|
|
149
|
+
}, 'Failed to query interface from remote peer');
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async call(serviceName, methodName, args) {
|
|
154
|
+
const service = await this.queryInterface(serviceName);
|
|
155
|
+
if (!service) {
|
|
156
|
+
throw Errors.notFound('Service', serviceName);
|
|
157
|
+
}
|
|
158
|
+
const method = service[methodName];
|
|
159
|
+
if (typeof method !== 'function') {
|
|
160
|
+
throw Errors.notFound('Method', `${serviceName}.${methodName}`);
|
|
161
|
+
}
|
|
162
|
+
return await method(...args);
|
|
163
|
+
}
|
|
164
|
+
async disconnect() {
|
|
165
|
+
if (this._state === ConnectionState.DISCONNECTED) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (this._state === ConnectionState.DISCONNECTING) {
|
|
169
|
+
this.logger.debug({ processId: this.processId }, 'Disconnect already in progress');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this._state = ConnectionState.DISCONNECTING;
|
|
173
|
+
if (this.reconnectTimer) {
|
|
174
|
+
clearTimeout(this.reconnectTimer);
|
|
175
|
+
this.reconnectTimer = undefined;
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
this.cleanup();
|
|
179
|
+
await this.netron.stop();
|
|
180
|
+
this._state = ConnectionState.DISCONNECTED;
|
|
181
|
+
this.logger.debug({ processId: this.processId }, 'Disconnected from process');
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
this.logger.error({ error, processId: this.processId }, 'Error during disconnect');
|
|
185
|
+
this._state = ConnectionState.FAILED;
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
cleanup() {
|
|
190
|
+
if (this.remotePeer) {
|
|
191
|
+
const peerAny = this.remotePeer;
|
|
192
|
+
if (this.disconnectHandler && typeof peerAny.off === 'function') {
|
|
193
|
+
peerAny.off('manual-disconnect', this.disconnectHandler);
|
|
194
|
+
}
|
|
195
|
+
this.disconnectHandler = undefined;
|
|
196
|
+
this.netron.peers.delete(this.remotePeer.id);
|
|
197
|
+
if (peerAny.transport && typeof peerAny.transport.close === 'function') {
|
|
198
|
+
peerAny.transport.close().catch((error) => {
|
|
199
|
+
this.logger.debug({ error, processId: this.processId }, 'Error closing transport');
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
this.remotePeer = undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
getNetron() {
|
|
206
|
+
return this.netron;
|
|
207
|
+
}
|
|
208
|
+
isConnected() {
|
|
209
|
+
return this._state === ConnectionState.CONNECTED;
|
|
210
|
+
}
|
|
211
|
+
createTimeout(ms, operation) {
|
|
212
|
+
return new Promise((_, reject) => {
|
|
213
|
+
setTimeout(() => {
|
|
214
|
+
reject(Errors.timeout(operation, ms));
|
|
215
|
+
}, ms);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
sleep(ms) {
|
|
219
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=netron-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"netron-client.js","sourceRoot":"","sources":["../src/netron-client.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAMpD,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,gDAA6B,CAAA;IAC7B,4CAAyB,CAAA;IACzB,0CAAuB,CAAA;IAC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B,CAAC;IACH,CAAC;IAKD,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAKD,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,eAAe,CAAC,SAAS,CAAC;IACnD,CAAC;IAKO,aAAa,CAAC,EAAU,EAAE,SAAiB;QACjD,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;YAC/B,UAAU,CAAC,GAAG,EAAE;gBACd,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;YACxC,CAAC,EAAE,EAAE,CAAC,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;IAKO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type DynamicModule, type Token } from '@omnitron-dev/titan/nexus';
|
|
2
|
+
import { ProcessManager } from './process-manager.js';
|
|
3
|
+
import { ProcessRegistry } from './process-registry.js';
|
|
4
|
+
import { ProcessSpawnerFactory } from './process-spawner.js';
|
|
5
|
+
import { ProcessMetricsCollector } from './process-metrics.js';
|
|
6
|
+
import { ProcessHealthChecker } from './process-health.js';
|
|
7
|
+
import type { IProcessManagerConfig } from './types.js';
|
|
8
|
+
export declare const PM_CONFIG_TOKEN: Token<IProcessManagerConfig>;
|
|
9
|
+
export declare const PM_MANAGER_TOKEN: Token<ProcessManager>;
|
|
10
|
+
export declare const PM_REGISTRY_TOKEN: Token<ProcessRegistry>;
|
|
11
|
+
export declare const PM_SPAWNER_TOKEN: Token<ProcessSpawnerFactory>;
|
|
12
|
+
export declare const PM_METRICS_TOKEN: Token<ProcessMetricsCollector>;
|
|
13
|
+
export declare const PM_HEALTH_TOKEN: Token<ProcessHealthChecker>;
|
|
14
|
+
export declare const DEFAULT_PM_CONFIG: IProcessManagerConfig;
|
|
15
|
+
export declare class ProcessManagerModule {
|
|
16
|
+
static forRoot(options?: IProcessManagerConfig): DynamicModule;
|
|
17
|
+
static forRootAsync(options: {
|
|
18
|
+
useFactory?: (...args: any[]) => Promise<IProcessManagerConfig> | IProcessManagerConfig;
|
|
19
|
+
inject?: any[];
|
|
20
|
+
useExisting?: any;
|
|
21
|
+
}): DynamicModule;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=pm.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pm.module.d.ts","sourceRoot":"","sources":["../src/pm.module.ts"],"names":[],"mappings":"AAOA,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAExF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAMxD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,qBAAqB,CAAkD,CAAC;AAC5G,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,cAAc,CAA4C,CAAC;AAChG,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,eAAe,CAA8C,CAAC;AACpG,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,qBAAqB,CAAmD,CAAC;AAC9G,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,uBAAuB,CAAqD,CAAC;AAClH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,oBAAoB,CAAiD,CAAC;AAK1G,eAAO,MAAM,iBAAiB,EAAE,qBA+B/B,CAAC;AAmBF,qBACa,oBAAoB;IAI/B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,qBAA0B,GAAG,aAAa;IA8ElE,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE;QAC3B,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,CAAC;QACxF,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;QACf,WAAW,CAAC,EAAE,GAAG,CAAC;KACnB,GAAG,aAAa;CAiElB"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var ProcessManagerModule_1;
|
|
8
|
+
import { createToken } from '@omnitron-dev/titan/nexus';
|
|
9
|
+
import { Module } from '@omnitron-dev/titan/decorators';
|
|
10
|
+
import { ProcessManager } from './process-manager.js';
|
|
11
|
+
import { ProcessRegistry } from './process-registry.js';
|
|
12
|
+
import { ProcessSpawnerFactory } from './process-spawner.js';
|
|
13
|
+
import { ProcessMetricsCollector } from './process-metrics.js';
|
|
14
|
+
import { ProcessHealthChecker } from './process-health.js';
|
|
15
|
+
import { LOGGER_SERVICE_TOKEN } from '@omnitron-dev/titan/module/logger';
|
|
16
|
+
export const PM_CONFIG_TOKEN = createToken('PMConfig');
|
|
17
|
+
export const PM_MANAGER_TOKEN = createToken('PMManager');
|
|
18
|
+
export const PM_REGISTRY_TOKEN = createToken('PMRegistry');
|
|
19
|
+
export const PM_SPAWNER_TOKEN = createToken('PMSpawner');
|
|
20
|
+
export const PM_METRICS_TOKEN = createToken('PMMetrics');
|
|
21
|
+
export const PM_HEALTH_TOKEN = createToken('PMHealth');
|
|
22
|
+
export const DEFAULT_PM_CONFIG = {
|
|
23
|
+
isolation: 'worker',
|
|
24
|
+
transport: 'unix',
|
|
25
|
+
restartPolicy: {
|
|
26
|
+
enabled: true,
|
|
27
|
+
maxRestarts: 3,
|
|
28
|
+
window: 60000,
|
|
29
|
+
delay: 1000,
|
|
30
|
+
backoff: {
|
|
31
|
+
type: 'exponential',
|
|
32
|
+
initial: 1000,
|
|
33
|
+
max: 30000,
|
|
34
|
+
factor: 2,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
resources: {
|
|
38
|
+
maxMemory: '512MB',
|
|
39
|
+
maxCpu: 1.0,
|
|
40
|
+
timeout: 30000,
|
|
41
|
+
},
|
|
42
|
+
monitoring: {
|
|
43
|
+
healthCheck: { interval: 30000, timeout: 5000 },
|
|
44
|
+
metrics: true,
|
|
45
|
+
tracing: false,
|
|
46
|
+
},
|
|
47
|
+
testing: {
|
|
48
|
+
useMockSpawner: false,
|
|
49
|
+
},
|
|
50
|
+
advanced: {
|
|
51
|
+
gracefulShutdownTimeout: 5000,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
let ProcessManagerModule = ProcessManagerModule_1 = class ProcessManagerModule {
|
|
55
|
+
static forRoot(options = {}) {
|
|
56
|
+
const config = {
|
|
57
|
+
...DEFAULT_PM_CONFIG,
|
|
58
|
+
...options,
|
|
59
|
+
restartPolicy: {
|
|
60
|
+
...DEFAULT_PM_CONFIG.restartPolicy,
|
|
61
|
+
...options.restartPolicy,
|
|
62
|
+
},
|
|
63
|
+
resources: {
|
|
64
|
+
...DEFAULT_PM_CONFIG.resources,
|
|
65
|
+
...options.resources,
|
|
66
|
+
},
|
|
67
|
+
monitoring: {
|
|
68
|
+
...DEFAULT_PM_CONFIG.monitoring,
|
|
69
|
+
...options.monitoring,
|
|
70
|
+
},
|
|
71
|
+
testing: {
|
|
72
|
+
...DEFAULT_PM_CONFIG.testing,
|
|
73
|
+
...options.testing,
|
|
74
|
+
},
|
|
75
|
+
advanced: {
|
|
76
|
+
...DEFAULT_PM_CONFIG.advanced,
|
|
77
|
+
...options.advanced,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
module: ProcessManagerModule_1,
|
|
82
|
+
providers: [
|
|
83
|
+
[PM_CONFIG_TOKEN, { useValue: config }],
|
|
84
|
+
[PM_REGISTRY_TOKEN, { useClass: ProcessRegistry }],
|
|
85
|
+
[
|
|
86
|
+
PM_SPAWNER_TOKEN,
|
|
87
|
+
{
|
|
88
|
+
useFactory: (loggerModule, pmConfig) => ProcessSpawnerFactory.create(loggerModule.logger ?? loggerModule, pmConfig),
|
|
89
|
+
inject: [LOGGER_SERVICE_TOKEN, PM_CONFIG_TOKEN],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
PM_METRICS_TOKEN,
|
|
94
|
+
{
|
|
95
|
+
useFactory: (loggerModule) => new ProcessMetricsCollector(loggerModule.logger ?? loggerModule),
|
|
96
|
+
inject: [LOGGER_SERVICE_TOKEN],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
PM_HEALTH_TOKEN,
|
|
101
|
+
{
|
|
102
|
+
useFactory: (loggerModule) => new ProcessHealthChecker(loggerModule.logger ?? loggerModule),
|
|
103
|
+
inject: [LOGGER_SERVICE_TOKEN],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
PM_MANAGER_TOKEN,
|
|
108
|
+
{
|
|
109
|
+
useFactory: (loggerModule, pmConfig) => new ProcessManager(loggerModule.logger ?? loggerModule, pmConfig),
|
|
110
|
+
inject: [LOGGER_SERVICE_TOKEN, PM_CONFIG_TOKEN],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
[ProcessManager, { useExisting: PM_MANAGER_TOKEN }],
|
|
114
|
+
],
|
|
115
|
+
exports: [ProcessManager, PM_MANAGER_TOKEN, PM_REGISTRY_TOKEN, PM_METRICS_TOKEN, PM_HEALTH_TOKEN],
|
|
116
|
+
global: true,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
static forRootAsync(options) {
|
|
120
|
+
const providers = [];
|
|
121
|
+
if (options.useFactory) {
|
|
122
|
+
providers.push([
|
|
123
|
+
PM_CONFIG_TOKEN,
|
|
124
|
+
{
|
|
125
|
+
useFactory: async (...args) => {
|
|
126
|
+
const config = await options.useFactory(...args);
|
|
127
|
+
return {
|
|
128
|
+
...DEFAULT_PM_CONFIG,
|
|
129
|
+
...config,
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
inject: options.inject || [],
|
|
133
|
+
},
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
else if (options.useExisting) {
|
|
137
|
+
providers.push([PM_CONFIG_TOKEN, { useExisting: options.useExisting }]);
|
|
138
|
+
}
|
|
139
|
+
providers.push([PM_REGISTRY_TOKEN, { useClass: ProcessRegistry }], [
|
|
140
|
+
PM_SPAWNER_TOKEN,
|
|
141
|
+
{
|
|
142
|
+
useFactory: (loggerModule, config) => ProcessSpawnerFactory.create(loggerModule.logger ?? loggerModule, config),
|
|
143
|
+
inject: [LOGGER_SERVICE_TOKEN, PM_CONFIG_TOKEN],
|
|
144
|
+
},
|
|
145
|
+
], [
|
|
146
|
+
PM_METRICS_TOKEN,
|
|
147
|
+
{
|
|
148
|
+
useFactory: (loggerModule) => new ProcessMetricsCollector(loggerModule.logger ?? loggerModule),
|
|
149
|
+
inject: [LOGGER_SERVICE_TOKEN],
|
|
150
|
+
},
|
|
151
|
+
], [
|
|
152
|
+
PM_HEALTH_TOKEN,
|
|
153
|
+
{
|
|
154
|
+
useFactory: (loggerModule) => new ProcessHealthChecker(loggerModule.logger ?? loggerModule),
|
|
155
|
+
inject: [LOGGER_SERVICE_TOKEN],
|
|
156
|
+
},
|
|
157
|
+
], [
|
|
158
|
+
PM_MANAGER_TOKEN,
|
|
159
|
+
{
|
|
160
|
+
useFactory: (loggerModule, config) => new ProcessManager(loggerModule.logger ?? loggerModule, config),
|
|
161
|
+
inject: [LOGGER_SERVICE_TOKEN, PM_CONFIG_TOKEN],
|
|
162
|
+
},
|
|
163
|
+
], [ProcessManager, { useExisting: PM_MANAGER_TOKEN }]);
|
|
164
|
+
return {
|
|
165
|
+
module: ProcessManagerModule_1,
|
|
166
|
+
providers: providers,
|
|
167
|
+
exports: [ProcessManager, PM_MANAGER_TOKEN, PM_REGISTRY_TOKEN, PM_METRICS_TOKEN, PM_HEALTH_TOKEN],
|
|
168
|
+
global: true,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
ProcessManagerModule = ProcessManagerModule_1 = __decorate([
|
|
173
|
+
Module()
|
|
174
|
+
], ProcessManagerModule);
|
|
175
|
+
export { ProcessManagerModule };
|
|
176
|
+
//# sourceMappingURL=pm.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pm.module.js","sourceRoot":"","sources":["../src/pm.module.ts"],"names":[],"mappings":";;;;;;;AAOA,OAAO,EAAE,WAAW,EAAkC,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,oBAA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+
import type { IHealthStatus, ServiceProxy, IProcessOptions } from './types.js';
|
|
4
|
+
export declare class ProcessHealthChecker extends EventEmitter {
|
|
5
|
+
private readonly logger;
|
|
6
|
+
private checkers;
|
|
7
|
+
private healthHistory;
|
|
8
|
+
private failureCounts;
|
|
9
|
+
constructor(logger: ILogger);
|
|
10
|
+
startMonitoring(processId: string, proxy: ServiceProxy<any>, options: IProcessOptions['health']): void;
|
|
11
|
+
stopMonitoring(processId: string): void;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
getHealth(processId: string): IHealthStatus | null;
|
|
14
|
+
getHealthHistory(processId: string): IHealthStatus[];
|
|
15
|
+
isHealthy(processId: string): boolean;
|
|
16
|
+
private performHealthCheck;
|
|
17
|
+
private checkHealth;
|
|
18
|
+
private basicHealthCheck;
|
|
19
|
+
private recordHealth;
|
|
20
|
+
private withTimeout;
|
|
21
|
+
private delay;
|
|
22
|
+
analyzeTrends(processId: string): {
|
|
23
|
+
trend: 'improving' | 'degrading' | 'stable';
|
|
24
|
+
availability: number;
|
|
25
|
+
avgResponseTime?: number;
|
|
26
|
+
};
|
|
27
|
+
getDegradationStrategy(processId: string): {
|
|
28
|
+
action: 'continue' | 'reduce_load' | 'circuit_break' | 'replace';
|
|
29
|
+
loadReductionPercent?: number;
|
|
30
|
+
reason: string;
|
|
31
|
+
};
|
|
32
|
+
shouldReduceLoad(processId: string): {
|
|
33
|
+
reduce: boolean;
|
|
34
|
+
percent: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=process-health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-health.d.ts","sourceRoot":"","sources":["../src/process-health.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,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