Commit 1dd67702 authored by project's avatar project

--no commit message

--no commit message
parent 7d3fd30a
......@@ -7,6 +7,7 @@ var amqp_cfg = ctx.config.amqp;
var ConnCtx = ctx.getLib('lib/conn/connection-context');
var CronList = ctx.getLib('lib/mems/cronlist');
var QueueCaller = ctx.getLib('lib/amqp/queuecaller');
var EvenSub = ctx.getLib('lib/amqp/event-sub');
module.exports.create = function (cfg)
{
......@@ -20,6 +21,7 @@ function SchedulerService(cfg)
this.conn = ConnCtx.create(this.config);
this.mem = this.conn.getMemstore();
this.jobcaller = new QueueCaller({'url':amqp_cfg.url,'name':'bs_jobs_queue'});
this.evs = new EvenSub({'url':amqp_cfg.url,'name':'bs_trigger_cmd'});
this.crons = CronList.create({'redis':this.mem});
this.engine = [];
......@@ -29,6 +31,7 @@ SchedulerService.prototype.start = function ()
{
console.log('SCHEDULER:Starting\t\t[OK]');
this.reload();
this._start_controller();
}
SchedulerService.prototype.reload = function ()
......@@ -40,11 +43,14 @@ SchedulerService.prototype.reload = function ()
var cl = self.crons.list;
for(var i=0;i<cl.length;i++)
{
var c = cl[i];
var s = schedule.scheduleJob(cl[i].cmd, function(y){
self._callJob(y);
}.bind(null,cl[i]));
self.engine.push(s);
self.engine.push({'c':c,'s':s});
}
console.log('SCHEDULER:Register ' + String(i) + ' jobs \t[OK]');
});
}
......@@ -54,7 +60,7 @@ SchedulerService.prototype.clean = function ()
var arrEngine = this.engine;
for(var i=0;i<arrEngine.length;i++)
{
arrEngine[i].cancel();
arrEngine[i].s.cancel();
}
this.engine = [];
}
......@@ -76,5 +82,26 @@ SchedulerService.prototype._callJob = function(cron)
}
this.jobcaller.send(cmd);
}
SchedulerService.prototype._start_controller = function ()
{
var self=this;
var topic = 'ctl.trigger.#';
self.evs.sub(topic,function(err,msg){
if(!msg){return;}
var ctl = msg.data;
if(ctl.trigger_type != 'cron' && ctl.trigger_type != 'all')
{
return;
}
if(ctl.cmd == 'reload')
{
console.log('SCHEDULER:CMD Reload\t\t[OK]');
self.reload();
}
});
}
......@@ -54,3 +54,9 @@ var cron = {
'cron':'*/10 * * * * *',
'jobid':'job01'
}
var trigger_cmd = {
'trigger_type' : 'cron',
'cmd' : 'reload',
'param':{}
}
......@@ -242,12 +242,3 @@ var client = redis.createClient('redis://bigmaster.igridproject.info:6379/1');
// crons.update(function(err){
// console.log(crons.list);
// });
var schedule = require('node-schedule');
var cron = '*/10 * * * * *';
var x = 'Tada!';
var j = schedule.scheduleJob(cron, function(y){
console.log(y);
}.bind(null,x));
x = 'Changing Data';
console.log(x);
......@@ -12,7 +12,7 @@ var qc = new QueueCaller({'url':amp,'name':'bs_jobs_queue'});
var cmd = {
'object_type':'job_execute',
'source' : 'http_listener',
'jobId' : 'job01',
'jobId' : 'job03',
'option' : {},
'input_data' : {
'type' : 'bsdata',
......
var ctx = require('../context');
var amqp_cfg = ctx.config.amqp;
var amp = 'amqp://lab1.igridproject.info';
var EvenPub = ctx.getLib('lib/amqp/event-pub');
var evp = new EvenPub({'url':amp,'name':'bs_trigger_cmd'});
var topic = 'ctl.trigger.all.reload';
var msg = {
'trigger_type' : 'all',
'cmd' : 'reload',
'prm' : {}
}
evp.send(topic,msg);
setTimeout(function(){
evp.close();
},500);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment