lib/job-manager.js
/*
 * runs the given subjob on the local machine
 * @param subjob {Object}: subjob description
 */
runs the given subjob on the local machine
@param subjob {Object}: subjob description
runs the given subjob on the local machine @param subjob { Object } : subjob description
function runLocally(subjob) {
    for(var i = 0; i < subjob.subsize; i++) {
        var rank = subjob.start + i;
        var jobInstance = cp.spawn('node', [subjob.app, subjob.size, rank], {
            stdio: [null, null, null, 'ipc']
        });
        var stdoutRlInterface = readline.createInterface({input: jobInstance.stdout});
        var stderrRlInterface = readline.createInterface({input: jobInstance.stderr});
        stdoutRlInterface.on('line', function(log) {
            router.routeToParent({type: "process:stdout", data: {line: log}});
        });
        stderrRlInterface.on('line', function(elog) {
            router.routeToParent({type: "process:stderr", data: {line: elog}});
        })
        jobInstance.on('exit', function(code) {
            router.routeToParent({type: "process:exit", data: {code: code}});
        });
        jobInstance.on('message', function(msg) {
            if(msg.type === 'klyng:msg') {
                router.routeTo(msg.header.to, msg);
            }
        });
        jobInstance.unref();
        router.setLocalChannel(rank, jobInstance);
    }
}
function runLocally ( subjob ) { for ( var i = 0 ; i < subjob . subsize ; i ++ ) { var rank = subjob . start + i ; var jobInstance = cp . spawn ( 'node' , [ subjob . app , subjob . size , rank ] , { stdio : [ null , null , null , 'ipc' ] } ) ; var stdoutRlInterface = readline . createInterface ( { input : jobInstance . stdout } ) ; var stderrRlInterface = readline . createInterface ( { input : jobInstance . stderr } ) ; stdoutRlInterface . on ( 'line' , function ( log ) { router . routeToParent ( { type : "process:stdout" , data : { line : log } } ) ; } ) ; stderrRlInterface . on ( 'line' , function ( elog ) { router . routeToParent ( { type : "process:stderr" , data : { line : elog } } ) ; } ) jobInstance . on ( 'exit' , function ( code ) { router . routeToParent ( { type : "process:exit" , data : { code : code } } ) ; } ) ; jobInstance . on ( 'message' , function ( msg ) { if ( msg . type === 'klyng:msg' ) { router . routeTo ( msg . header . to , msg ) ; } } ) ; jobInstance . unref ( ) ; router . setLocalChannel ( rank , jobInstance ) ; } }
runs the given subjob on the local machine
 @param subjob {Object}: subjob description
runs the given subjob on the local machine @param subjob { Object } : subjob description
// register a handler for instance's stdout data // reports back to the parent klyng process // register a handler for instance's stderr data // reports back to the parent klyng process // register a handler for instance exit event // reports back to the parent klyng process // register a handler for instance's messages