@mdf.js/service-registry
Version:
MMS - API - Service Registry
64 lines • 2.8 kB
TypeScript
/**
* Copyright 2024 Mytra Control S.L. All rights reserved.
*
* Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
* or at https://opensource.org/licenses/MIT.
*/
import { LoggerInstance } from '@mdf.js/logger';
import { Aggregator } from '../Aggregator';
import { Port } from './Port';
/**
* MasterPort class manages the collection and aggregation of error records from worker processes
* in a clustered environment. It periodically requests error registries from each worker,
* aggregates the errors, and updates the main aggregator instance with the collected errors.
*
* Inherits from the Port class, utilizing its logging capabilities and defining additional
* mechanisms for inter-process communication and error aggregation specific to the master process.
*/
export declare class MasterPort extends Port {
private readonly aggregator;
private readonly interval;
/** Request sequence number */
private requestId;
/** Timeout interval handler for master polling */
private timeInterval?;
/**
* Create an instance of errors manager in a master process
* @param aggregator - Aggregator instance to manage the errors
* @param logger - Logger instance for logging activities
* @param interval - interval in milliseconds between each error registry poll from workers.
*/
constructor(aggregator: Aggregator, logger: LoggerInstance, interval?: number);
/**
* Starts the process of periodically polling error registries from worker processes.
* Ensures that only one polling mechanism is active at any given time.
*/
start(): void;
/**
* Stops the polling of error registries from worker processes and clears the polling interval.
*/
stop(): void;
/**
* Clears all error registries, both in the master and in all connected worker processes.
*/
clear(): void;
/**
* Sends a request to all worker processes to send their current error registries.
* Handles responses, timeouts, and updates the aggregator with aggregated errors from workers.
*/
private readonly onSendRequest;
/**
* Merges the errors received from a worker process into the accumulated error records.
* Adds worker identification details to each error record for traceability.
* @param feed - feed to be merged with the errors from the worker
* @param worker - Worker that emit the errors
* @param workerErrors - errors from the worker
*/
private mergeErrors;
/**
* Retrieves a dictionary of currently active worker processes.
* @returns A dictionary of Worker instances indexed by their cluster worker ID.
*/
private get workers();
}
//# sourceMappingURL=MasterPort.d.ts.map