mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add strong-cluster-control typing files (#14128)
This commit is contained in:
parent
696932988b
commit
0b60775142
98
strong-cluster-control/index.d.ts
vendored
Normal file
98
strong-cluster-control/index.d.ts
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
// Type definitions for strong-cluster-control 2.2
|
||||
// Project: https://github.com/strongloop/strong-cluster-control
|
||||
// Definitions by: Shun Takahashi <https://github.com/shuntksh>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference types="node" />
|
||||
|
||||
declare namespace StrongClusterControl {
|
||||
type pid = number;
|
||||
|
||||
export interface StartOptions {
|
||||
size?: number;
|
||||
env?: {};
|
||||
shutdownTimeout?: number;
|
||||
terminateTimeout?: number;
|
||||
throttleDelay?: number;
|
||||
}
|
||||
|
||||
export interface ClusterMaster {
|
||||
pid: number;
|
||||
setSize?: number;
|
||||
startTime: number;
|
||||
}
|
||||
|
||||
export interface ClusterWorker extends ClusterMaster {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export interface ClusterStatus {
|
||||
master: ClusterMaster;
|
||||
workers: ClusterWorker[];
|
||||
}
|
||||
|
||||
interface CMD {
|
||||
SHUTDOWN: "CLUSTER_CONTROL_shutdown";
|
||||
}
|
||||
|
||||
export interface Control extends NodeJS.EventEmitter {
|
||||
readonly cmd: CMD;
|
||||
readonly CPUS: number;
|
||||
readonly options: StartOptions;
|
||||
|
||||
/**
|
||||
* @description Start the controller
|
||||
* @param [options] - An options object, no default, and options object is not required.
|
||||
* @param [options.size] - Number of workers that should be running, the default is to not control the number of workers
|
||||
* @param [options.env=null] - Environment properties object passed to cluster.fork() if the controller has to start a worker to resize the cluster, default is null.
|
||||
* @param [options.shutdownTimeout=5000] - Number of milliseconds to wait after shutdown before terminating a worker, the default is 5 seconds
|
||||
* @param [options.terminateTimeout=5000] - Number of milliseconds to wait after terminate before killing a worker, the default is 5 seconds
|
||||
* @param [options.throttoleDelay] - Number of milliseconds to delay restarting workers after they are exiting abnormally. Abnormal is defined as as not suicide.
|
||||
*/
|
||||
start(options?: StartOptions, callback?: () => any): this;
|
||||
start(callback?: () => any): this;
|
||||
|
||||
/**
|
||||
* @description Stop the controller, after stopping workers (if the size is being controlled, see setSize()).
|
||||
* @param callback
|
||||
*/
|
||||
stop(callback?: () => any): this;
|
||||
|
||||
/**
|
||||
* @description Restart workers one by one, until all current workers have been restarted.
|
||||
*/
|
||||
restart(): this;
|
||||
|
||||
/**
|
||||
* @description Returns the current cluster status
|
||||
*/
|
||||
status(): ClusterStatus;
|
||||
|
||||
/**
|
||||
* @description Set the size of the cluster.
|
||||
* @param N - The size of the cluster is the number of workers that should be maintained online.
|
||||
*/
|
||||
setSize(N?: number): this;
|
||||
|
||||
/**
|
||||
* @description Disconnect worker id and take increasingly agressive action until it exits.
|
||||
* @param id - Cluster worker ID,
|
||||
*/
|
||||
shutdown(id: number): this;
|
||||
|
||||
/**
|
||||
* @description Disconnect worker id and take increasingly agressive action until it exits.
|
||||
* @param id - Cluster worker ID,
|
||||
*/
|
||||
terminate(id: number): this;
|
||||
|
||||
on(event: "start" | "stop" | "restart", handler: () => any): this;
|
||||
on(event: "setSize" | "resize", handler: (size: number) => any): this;
|
||||
on(event: "startWorker", handler: (worker: ClusterWorker) => any): this;
|
||||
on(event: "startRestart", handler: (workers: pid[]) => any): this;
|
||||
on(event: "stopWorker", handler: (worker: ClusterWorker, code: number, signal: string) => any): this;
|
||||
on(event: "error", handler: (error: Error | Error[]) => any): this;
|
||||
}
|
||||
}
|
||||
|
||||
declare const control: StrongClusterControl.Control;
|
||||
export = control;
|
||||
30
strong-cluster-control/strong-cluster-control-tests.ts
Normal file
30
strong-cluster-control/strong-cluster-control-tests.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import * as control from "strong-cluster-control";
|
||||
|
||||
control.start({ size: control.CPUS}, (): void => { console.log("starting"); })
|
||||
.on("error", (err: Error): void => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
control.start((): void => { console.log("staring"); })
|
||||
.on("error", (err: Error): void => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
control.stop()
|
||||
.on("stop", (): void => {
|
||||
console.log("stopped");
|
||||
});
|
||||
|
||||
control.setSize(2)
|
||||
.on("setSize", (size) => console.log(size))
|
||||
.on("resize", (size) => console.log(size));
|
||||
|
||||
control.restart()
|
||||
.on("startRestart", (pids) => console.log(`Restarting ${pids.length} workers`))
|
||||
.on("restart", () => console.log("restarted"));
|
||||
|
||||
control.shutdown(123)
|
||||
.on("stopWorker", (worker) => console.log(`Worker ${worker.pid} stopped`));
|
||||
|
||||
control.terminate(123)
|
||||
.on("stopWorker", (worker) => console.log(`Worker ${worker.pid} stopped`));
|
||||
20
strong-cluster-control/tsconfig.json
Normal file
20
strong-cluster-control/tsconfig.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"strong-cluster-control-tests.ts"
|
||||
]
|
||||
}
|
||||
1
strong-cluster-control/tslint.json
Normal file
1
strong-cluster-control/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Loading…
Reference in New Issue
Block a user