-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
137 lines (98 loc) · 3.07 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { EventEmitter } from "node:stream";
import { IncomingMessage, ServerResponse, Server } from "node:http";
import { Worker as NodeWorker } from 'node:worker_threads';
import bunyan from "bunyan";
export class Status {
name: string | null;
parent: Status | null;
constructor();
set(key: string | Record<string, any>, value: any): void;
increment(name: string, increment?: number, destObj?: Record<string, any>, aggregates?: Record<string, string>): void;
setIncrement(name: string, value: any): void;
onStatus(callback: () => void): void;
child(name: string): Status;
addChild(name: string): Status;
close(): void;
getStatus(): Record<string, any>;
setStatus(status: Record<string, any>): void;
}
type WorkerOptions = {
shutdownTimeout?: number,
log?: bunyan,
httpServer?: Server,
};
interface WorkerEventMap {
close: [];
}
export class Worker extends EventEmitter<WorkerEventMap> {
status: Status;
constructor(opts?: WorkerOptions);
/**
* Tell the master that the worker is ready.
*
* This function needs to be called before `startupTimeout` is over, otherwise the worker
* is assumed to failed to start and thus being killed by the master process.
*/
ready(): void;
/**
* Attach to an exising HTTP server.
*
* This may be necessary after creating the Worker instance, so we can instantiate the
* http.Server later.
*/
attach(server: Server): void;
/**
* Shutdown the worker
*/
shutdown(): void;
logActiveHandles(): void;
onRequest(request: IncomingMessage, response: ServerResponse): void;
onConnection(connection: IncomingMessage['connection']): void;
onCloseServer(): void;
sendStatus(): void;
send(message: unknown): void;
/**
* Retrieve the cluster status
*/
serverStatus(): Promise<void>;
}
type MasterOptions<WorkerArguments extends Array<unknown> = Array<unknown>> = {
exec: string,
/**
* @default os.cpus().length
*/
workers?: number,
args?: WorkerArguments,
startupTimeout?: number,
shutdownTimeout?: number,
silent?: boolean,
logger?: bunyan,
beforeReload?: () => Promise<void>,
beforeShutdown?: () => Promise<void>,
};
interface MasterEventMap {
init: [];
shutdown: [];
}
export class Master<WorkerArguments extends Array<unknown> = Array<unknown>> extends EventEmitter<MasterEventMap> {
constructor(opts?: MasterOptions<WorkerArguments>);
run(): void;
reload(): Promise<void>;
/**
* Set the cluster config. Merges config values into the existing config
*/
setConfig(opts: Record<string, unknown>): void;
readjustCluster(): void;
onFork(worker: NodeWorker): void;
shutdownWorker(worker: NodeWorker): void;
setWorkerKillTimeout(worker: NodeWorker, type: string): void;
notifyServerStatus(timeoutReached: boolean): void;
/**
* Shutdown the cluster.
*/
shutdown(): Promise<void>;
/**
* Retrieve the cluster status.
*/
serverStatus(): Promise<void>;
}