core-services/uBroker/index.js
function selectService (service){

    if(typeof(uServices[service]) !== 'undefined'){

        if (uServices[service].length !== 0 ) {
            var uService = uServices[service], //array
                activeuService = uService[0];
            // the first service should be active but if is not, should look for an active one
            if (activeuService.status == 0) {
                var foundOne = false;
                for ( var i = 0 ; i < uService.length ; i++ ){
                    if ( foundOne == false && uService[i].status == 1 ) {
                        activeuService = uService[i];
                        foundOne = true;
                    }
                }
                //if there is not active service just stay whith the first one
            }

            activeuService.status = 0;     //change state to busy

            uService.shift();              //take the service out of the list
            uService.push(activeuService); // pushing the service at the end of the list
            uService[0].status = 1;        //activate other service

            //save the new uServices
            uServices[service] = uService;

            // changing the variable on redis
            client.set('uServices', JSON.stringify(uServices));
            // Publish that it did an update
            client.publish('uServicesChannel', 'UPDATE');
            return activeuService;

        } else {
            //not services availables
            console.log('Not services %s available', service);
            //return error to broker
            return 'Not services '+service+' available'
        }

    } else {
        return "not services with name "+service;
        // return an error cause there are no services with that name
    }
}
function selectService (service){

    if(typeof(uServices[service]) !== 'undefined'){

        if (uServices[service].length !== 0 ) {
            var uService = uServices[service], //array
                activeuService = uService[0];
            // the first service should be active but if is not, should look for an active one
            if (activeuService.status == 0) {
                var foundOne = false;
                for ( var i = 0 ; i < uService.length ; i++ ){
                    if ( foundOne == false && uService[i].status == 1 ) {
                        activeuService = uService[i];
                        foundOne = true;
                    }
                }
                //if there is not active service just stay whith the first one
            }

            activeuService.status = 0;     //change state to busy

            uService.shift();              //take the service out of the list
            uService.push(activeuService); // pushing the service at the end of the list
            uService[0].status = 1;        //activate other service

            //save the new uServices
            uServices[service] = uService;

            // changing the variable on redis
            client.set('uServices', JSON.stringify(uServices));
            // Publish that it did an update
            client.publish('uServicesChannel', 'UPDATE');
            return activeuService;

        } else {
            //not services availables
            console.log('Not services %s available', service);
            //return error to broker
            return 'Not services '+service+' available'
        }

    } else {
        return "not services with name "+service;
        // return an error cause there are no services with that name
    }
}
function selectService ( service ) { if ( typeof ( uServices [ service ] ) !== 'undefined' ) { if ( uServices [ service ] . length !== 0 ) { var uService = uServices [ service ] , //array activeuService = uService [ 0 ] ; // the first service should be active but if is not, should look for an active one if ( activeuService . status == 0 ) { var foundOne = false ; for ( var i = 0 ; i < uService . length ; i ++ ) { if ( foundOne == false && uService [ i ] . status == 1 ) { activeuService = uService [ i ] ; foundOne = true ; } } //if there is not active service just stay whith the first one } activeuService . status = 0 ; //change state to busy uService . shift ( ) ; //take the service out of the list uService . push ( activeuService ) ; // pushing the service at the end of the list uService [ 0 ] . status = 1 ; //activate other service //save the new uServices uServices [ service ] = uService ; // changing the variable on redis client . set ( 'uServices' , JSON . stringify ( uServices ) ) ; // Publish that it did an update client . publish ( 'uServicesChannel' , 'UPDATE' ) ; return activeuService ; } else { //not services availables console . log ( 'Not services %s available' , service ) ; //return error to broker return 'Not services ' + service + ' available' } } else { return "not services with name " + service ; // return an error cause there are no services with that name } }
Select a service to assign a job and activate the next service
@param service
@returns {*}
Select a service to assign a job and activate the next service