@mediarithmics/plugins-nodejs-sdk
Version:
This is the mediarithmics nodejs to help plugin developers bootstrapping their plugin without having to deal with most of the plugin boilerplate
43 lines (42 loc) • 1.77 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import { Worker } from 'cluster';
import { Server } from 'http';
import { BasePlugin } from './BasePlugin';
export declare enum MsgCmd {
LOG_LEVEL_UPDATE_FROM_WORKER = 0,
LOG_LEVEL_UPDATE_FROM_MASTER = 1,
GET_LOG_LEVEL_REQUEST = 2
}
export interface SocketMsg {
cmd: MsgCmd;
value?: string;
}
export declare class ProductionPluginRunner {
numCPUs: number;
pluginPort: number;
plugin: BasePlugin;
server: Server;
constructor(plugin: BasePlugin);
updatePluginLogLevel: (value: string) => void;
broadcastLogLevelToWorkers: () => void;
/**
* Socker Listener for master process. It has 4 jobs:
* 1 - If a new token is detected by a Worker, it receives a message and should send a message to each workers
* 2 - If a worker is asking for a token update (ex: the worker was just created because one of his friends died), the master should send a message to each workers
* 3 - If a log level change is detected by a worker, it receives a message and should send a message to each workers
* 4 - If a worker is asking for a log level update (ex: the worker was just created because one of his friends died), the master should send a message to each workers
* @param recMsg
*/
masterListener: (worker: Worker, recMsg: SocketMsg) => void;
/**
* Socker Listener of the workers. It should listen for Token update from master and for Log Level changes
* @param recMsg
*/
workerListener: (recMsg: SocketMsg) => void;
/**
* Multi threading launch of the App, with socket communicaton to propagate token updates
* @param port
*/
start(port?: number, multiProcessEnabled?: boolean): void;
}