コード例 #1
0
ファイル: tule-cron.js プロジェクト: arqex/tule-cron
	addCron: function( filepath ){
		try {
			var cron = require( filepath );

			if( !cron || !cron.job )
				return logger.error( 'Cron has no job', {filename: filepath} );

			var interval = cron.interval || config.cron.defaultInterval,
				job = new CronJob( interval, cron.job )
			;

			this.crons[ filepath ] = {
				job: job,
				method: cron.job,
				interval: interval
			};

			if( cron.runOnAdding ){
				cron.job();
			}
		}
		catch (e) {
			return logger.error( 'Cron error', e.stack );
		}
	},
コード例 #2
0
ファイル: job.js プロジェクト: cloneMe/explorer
    debug('Require %s', args[i])

    let tmp = require(args[i])
    let title = tmp.name

    if(!title) {
      title = p.basename(args[i]) 
    }
    
    if(plugins[title]) {
      throw new ReferenceError("Plugin " + title + " is already registered")
    }

    if('job' in tmp)
      plugins[title] = tmp.job(ipc)

  } catch(e) {
    console.error('Could not require plugin (export a function) %s', args[i])
    if(config.dev)
      console.error(e.stack) 
  }
}

var names = Object.keys(plugins)

/**
 * Transforms something like class.method or method to callable elements
 * @param string element 
 * @return object {method: MethodToBeCalled, items: array of plugins in which we'll call method, item: if only one}
 */