lib/daemon/injector.js
function Injector(conf) {
  component.Component.call(this, 'injector', conf);
  var that = this;
  this._default_controller = defaults.controllerfuncname(conf);
  this._dbconn = conf.dbconn;
  this.registerGearman(conf.servers, {
    worker: {
      func_name: 'submitJobDelayed',
      func: function(payload, worker) {
        var task;
        try {
          task = JSON.parse(payload);
        } catch (err) {
          that._err('Error:', err.message);
          worker.done(that.component_name + ': ' + err.message);
          return;
        }

        that._info('Received a task for',
            (task.controller || that._default_controller) +
            '/' + task.func_name);
        // TODO: Properly abstract date handling into lib/gearsloth.js and handle
        // invalid dates etc.
        if ('at' in task) {
          task.at = new Date(task.at);
          if (isNaN(task.at.getTime())) {
            worker.done(that.component_name + ': invalid date format.');
            return;
          }
        }
        if ('after' in task && isNaN(task.after)) {
          worker.done(that.component_name + ': invalid \'after\' format.');
          return;
        }
        if (! ('func_name' in task)) {
          worker.done(that.component_name +
              ': no function name (func_name) defined in task.');
          return;
        }
        that.inject(task, worker);
      }
    }
  });
}
function Injector(conf) {
  component.Component.call(this, 'injector', conf);
  var that = this;
  this._default_controller = defaults.controllerfuncname(conf);
  this._dbconn = conf.dbconn;
  this.registerGearman(conf.servers, {
    worker: {
      func_name: 'submitJobDelayed',
      func: function(payload, worker) {
        var task;
        try {
          task = JSON.parse(payload);
        } catch (err) {
          that._err('Error:', err.message);
          worker.done(that.component_name + ': ' + err.message);
          return;
        }

        that._info('Received a task for',
            (task.controller || that._default_controller) +
            '/' + task.func_name);
        // TODO: Properly abstract date handling into lib/gearsloth.js and handle
        // invalid dates etc.
        if ('at' in task) {
          task.at = new Date(task.at);
          if (isNaN(task.at.getTime())) {
            worker.done(that.component_name + ': invalid date format.');
            return;
          }
        }
        if ('after' in task && isNaN(task.after)) {
          worker.done(that.component_name + ': invalid \'after\' format.');
          return;
        }
        if (! ('func_name' in task)) {
          worker.done(that.component_name +
              ': no function name (func_name) defined in task.');
          return;
        }
        that.inject(task, worker);
      }
    }
  });
}
function Injector ( conf ) { component . Component . call ( this , 'injector' , conf ) ; var that = this ; this . _default_controller = defaults . controllerfuncname ( conf ) ; this . _dbconn = conf . dbconn ; this . registerGearman ( conf . servers , { worker : { func_name : 'submitJobDelayed' , func : function ( payload , worker ) { var task ; try { task = JSON . parse ( payload ) ; } catch ( err ) { that . _err ( 'Error:' , err . message ) ; worker . done ( that . component_name + ': ' + err . message ) ; return ; } that . _info ( 'Received a task for' , ( task . controller || that . _default_controller ) + '/' + task . func_name ) ; // TODO: Properly abstract date handling into lib/gearsloth.js and handle // invalid dates etc. if ( 'at' in task ) { task . at = new Date ( task . at ) ; if ( isNaN ( task . at . getTime ( ) ) ) { worker . done ( that . component_name + ': invalid date format.' ) ; return ; } } if ( 'after' in task && isNaN ( task . after ) ) { worker . done ( that . component_name + ': invalid \'after\' format.' ) ; return ; } if ( ! ( 'func_name' in task ) ) { worker . done ( that . component_name + ': no function name (func_name) defined in task.' ) ; return ; } that . inject ( task , worker ) ; } } } ) ; }
Injector component. Emits 'connect' when at least one server is connected.
Injector component . Emits connect when at least one server is connected .