lib/worker-manager.js
function stopWorker(worker){
    return new Promise(function(resolve, reject){
        // set kill timeout
        const killTimeout = setTimeout(() => {
            // kill the worker
            worker.kill();
            
            // failed to disconnect within given time
            reject(new Error(`process ${worker.process.pid} killed by timeout of ${_workerShutdownTimeout/1000}s - disconnect() failed`));
        }, _workerShutdownTimeout);

        // wait for exit + disconnect
        worker.on('disconnect', () => {
            _logger.log(`disconnect event ${worker.process.pid}`);
            // disable kill timer
            clearTimeout(killTimeout);

            // ok
            resolve();
        });

        // trigger disconnect
        worker.disconnect();
    });
}
function stopWorker(worker){
    return new Promise(function(resolve, reject){
        // set kill timeout
        const killTimeout = setTimeout(() => {
            // kill the worker
            worker.kill();
            
            // failed to disconnect within given time
            reject(new Error(`process ${worker.process.pid} killed by timeout of ${_workerShutdownTimeout/1000}s - disconnect() failed`));
        }, _workerShutdownTimeout);

        // wait for exit + disconnect
        worker.on('disconnect', () => {
            _logger.log(`disconnect event ${worker.process.pid}`);
            // disable kill timer
            clearTimeout(killTimeout);

            // ok
            resolve();
        });

        // trigger disconnect
        worker.disconnect();
    });
}
function stopWorker ( worker ) { return new Promise ( function ( resolve , reject ) { // set kill timeout const killTimeout = setTimeout ( ( ) => { // kill the worker worker . kill ( ) ; // failed to disconnect within given time reject ( new Error ( ` ${ worker . process . pid } ${ _workerShutdownTimeout / 1000 } ` ) ) ; } , _workerShutdownTimeout ) ; // wait for exit + disconnect worker . on ( 'disconnect' , ( ) => { _logger . log ( ` ${ worker . process . pid } ` ) ; // disable kill timer clearTimeout ( killTimeout ) ; // ok resolve ( ) ; } ) ; // trigger disconnect worker . disconnect ( ) ; } ) ; }
worker gracefull shutdown
worker gracefull shutdown