lib/worker-manager.js
function startWorker(triggeredByError=false){
    return new Promise(function(resolve){
        // default restart delay
        let restartDelay = 0;

        // worker restart because of died process ?
        if (triggeredByError === true){
            // increment restart counter
            _restartCounter++;
        }

        // delayed restart ?
        if (_restartCounter > 10){
            // calculate restart delay (min: 2s)
            restartDelay = 200 * _restartCounter;

            // trigger alert message
            _logger.alert(`delayed worker-restart of ${restartDelay/1000}s - number of failed processes: ${_restartCounter}`);
        }

        // trigger async fork
        setTimeout(() => {
            // create a new child process
            // note: this method RELOADS the entire js file/module! - it is NOT a classical process.fork() !
            // this allows you to hot-reload your application by restarting the workers
            const worker = _cluster.fork();

            // return worker
            resolve(worker);

        }, restartDelay);
    });
}
function startWorker(triggeredByError=false){
    return new Promise(function(resolve){
        // default restart delay
        let restartDelay = 0;

        // worker restart because of died process ?
        if (triggeredByError === true){
            // increment restart counter
            _restartCounter++;
        }

        // delayed restart ?
        if (_restartCounter > 10){
            // calculate restart delay (min: 2s)
            restartDelay = 200 * _restartCounter;

            // trigger alert message
            _logger.alert(`delayed worker-restart of ${restartDelay/1000}s - number of failed processes: ${_restartCounter}`);
        }

        // trigger async fork
        setTimeout(() => {
            // create a new child process
            // note: this method RELOADS the entire js file/module! - it is NOT a classical process.fork() !
            // this allows you to hot-reload your application by restarting the workers
            const worker = _cluster.fork();

            // return worker
            resolve(worker);

        }, restartDelay);
    });
}
function startWorker ( triggeredByError = false ) { return new Promise ( function ( resolve ) { // default restart delay let restartDelay = 0 ; // worker restart because of died process ? if ( triggeredByError === true ) { // increment restart counter _restartCounter ++ ; } // delayed restart ? if ( _restartCounter > 10 ) { // calculate restart delay (min: 2s) restartDelay = 200 * _restartCounter ; // trigger alert message _logger . alert ( ` ${ restartDelay / 1000 } ${ _restartCounter } ` ) ; } // trigger async fork setTimeout ( ( ) => { // create a new child process // note: this method RELOADS the entire js file/module! - it is NOT a classical process.fork() ! // this allows you to hot-reload your application by restarting the workers const worker = _cluster . fork ( ) ; // return worker resolve ( worker ) ; } , restartDelay ) ; } ) ; }
start a new worker
start a new worker