lib/cli-controller.js
/*
 * initaites a specified klyng job
 * signals the beacon process to spawn the parallel process
 * starts listening for control and monitoring messages from the beacon
 * @param job {Object}: the klyng job description
 */
initaites a specified klyng job
signals the beacon process to spawn the parallel process
starts listening for control and monitoring messages from the beacon
@param job {Object}: the klyng job description
initaites a specified klyng job signals the beacon process to spawn the parallel process starts listening for control and monitoring messages from the beacon @param job { Object } : the klyng job description
function run(job) {
    beacon.checkIfRunning()
    .then(function(running) {
        if(running) {
            return true;
        }
        else {
            return beacon.start();
        }
    })
    .then(function(started) {
        if(started) {
            return beacon.signalToRun(job);
        }
        else {
            console.error("Failed to start or connect to beacon.");
        }
    })
    .then(function(signaled) {
        if(signaled) {
            if(signaled === 'busy') {
                console.log('The beacon is busy.');
                ipc.disconnect('klyng_beacon');
            }
            else {
                var remainingProcessesCount = job.size;
                ipc.of.klyng_beacon.on('MONITOR:MSG', function(message, socket) {
                    if(message.type === 'process:stdout') {
                        console.log(message.data.line);
                    }
                    if(message.type === 'process:stderr') {
                        console.error(message.data.line);
                    }
                    else if(message.type === 'process:exit') {
                        remainingProcessesCount--;
                        if(!remainingProcessesCount)
                            beacon.signalDone()
                    }
                    else if(message.type === 'job:aborted') {
                        console.error("[Aborted]: %s", message.reason);
                        ipc.disconnect('klyng_beacon');
                    }
                });
            }
        }
    });
}
function run ( job ) { beacon . checkIfRunning ( ) . then ( function ( running ) { if ( running ) { return true ; } else { return beacon . start ( ) ; } } ) . then ( function ( started ) { if ( started ) { return beacon . signalToRun ( job ) ; } else { console . error ( "Failed to start or connect to beacon." ) ; } } ) . then ( function ( signaled ) { if ( signaled ) { if ( signaled === 'busy' ) { console . log ( 'The beacon is busy.' ) ; ipc . disconnect ( 'klyng_beacon' ) ; } else { var remainingProcessesCount = job . size ; ipc . of . klyng_beacon . on ( 'MONITOR:MSG' , function ( message , socket ) { if ( message . type === 'process:stdout' ) { console . log ( message . data . line ) ; } if ( message . type === 'process:stderr' ) { console . error ( message . data . line ) ; } else if ( message . type === 'process:exit' ) { remainingProcessesCount -- ; if ( ! remainingProcessesCount ) beacon . signalDone ( ) } else if ( message . type === 'job:aborted' ) { console . error ( "[Aborted]: %s" , message . reason ) ; ipc . disconnect ( 'klyng_beacon' ) ; } } ) ; } } } ) ; }
initaites a specified klyng job
 signals the beacon process to spawn the parallel process
 starts listening for control and monitoring messages from the beacon
 @param job {Object}: the klyng job description
initaites a specified klyng job signals the beacon process to spawn the parallel process starts listening for control and monitoring messages from the beacon @param job { Object } : the klyng job description