@@ -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