New typings for recluster

This commit is contained in:
Piotr Roszatycki
2018-02-20 22:20:11 +01:00
parent 070eb128b8
commit 8183457f0c
4 changed files with 80 additions and 0 deletions

46
types/recluster/index.d.ts vendored Normal file
View File

@@ -0,0 +1,46 @@
// Type definitions for recluster 0.4
// Project: https://github.com/doxout/recluster
// Definitions by: Piotr Roszatycki <https://github.com/dex4er>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { ChildProcess } from "child_process";
export interface LogOptions {
respawns?: boolean;
}
export interface Logger {
log(message?: any, ...optionalParams: any[]): void;
}
export interface BalancerOptions {
/** number of active workers */
workers?: number;
/** kill timeout for old workers after reload (sec) */
timeout?: number;
/** min time between respawns when workers die */
respawn?: number;
/** max time between respawns when workers die */
backoff?: number;
/** when does the worker become ready? 'listening' or 'started' */
readyWhen?: string;
/** arguments to pass to the worker (default: []) */
args?: string[];
/** what to log to stdout (default: {respawns: true}) */
log?: LogOptions;
/** logger to use, needs `log` method (default: console) */
logger?: Logger;
}
export class Balancer {
constructor(file: string, options: BalancerOptions);
run(): void;
reload(cb?: () => void): void;
stop(): void;
workers(): ChildProcess[];
activeWorkers(): ChildProcess[];
}
export default function recluster(file: string, options?: BalancerOptions): Balancer;

View File

@@ -0,0 +1,9 @@
import recluster from "recluster";
import path = require("path");
const cluster = recluster(path.join(__dirname, 'server.js'));
cluster.run();
process.on('SIGUSR2', () => {
cluster.reload();
});

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
},
"files": [
"index.d.ts",
"recluster-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }