Skip to content

Commit 535eb18

Browse files
author
ionut.stan
committed
start and stop services.
1 parent 33c24bb commit 535eb18

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jsonrpc-bidirectional",
33
"description": "Bidirectional JSONRPC over web sockets or HTTP with extensive plugin support.",
4-
"version": "5.7.0",
4+
"version": "5.7.1",
55
"scripts": {
66
"build": "node build.js",
77
"test": "node --expose-gc --max-old-space-size=1024 tests/main.js",

src/NodeClusterBase/MasterEndpoint.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,41 @@ class MasterEndpoint extends JSONRPC.EndpointBase
6464
}
6565

6666

67+
/**
68+
* This overridable function is called and awaited inside startWorker().
69+
*
70+
* This mustn't be called through JSONRPC.
71+
*
72+
* @param {undefined} incomingRequest
73+
*/
74+
async _startServices(incomingRequest)
75+
{
76+
if(incomingRequest)
77+
{
78+
throw new Error("This mustn't be called through JSONRPC.");
79+
}
80+
81+
// this.masterClient is available here.
82+
}
83+
84+
85+
/**
86+
* This overridable function is called and awaited inside gracefulExit().
87+
* Careful, gracefulExit() will timeout waiting after services to stop after a while.
88+
*
89+
* This mustn't be called through JSONRPC.
90+
*
91+
* @param {undefined} incomingRequest
92+
*/
93+
async _stopServices(incomingRequest)
94+
{
95+
if(incomingRequest)
96+
{
97+
throw new Error("This mustn't be called through JSONRPC.");
98+
}
99+
}
100+
101+
67102
/**
68103
* Starts the JSONRPC server over cluster IPC, and forks worker processes.
69104
*/
@@ -142,6 +177,8 @@ class MasterEndpoint extends JSONRPC.EndpointBase
142177
}
143178
);
144179

180+
await this._startServices();
181+
145182
for (let i = 0; i < Math.max(os.cpus().length, 2); i++)
146183
{
147184
cluster.fork();
@@ -280,6 +317,7 @@ class MasterEndpoint extends JSONRPC.EndpointBase
280317
}
281318
console.log("All workers have exited.");
282319

320+
await this._stopServices();
283321

284322
console.log("[" + process.pid + "] Master process exiting gracefully.");
285323
process.exit(0);

0 commit comments

Comments
 (0)