Commit ec9c42de authored by project's avatar project

--no commit message

--no commit message
parent c37e0374
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
"dateformat": "^1.0.12", "dateformat": "^1.0.12",
"express": "^4.14.0", "express": "^4.14.0",
"node-persist": "^2.0.7", "node-persist": "^2.0.7",
"node-schedule": "^1.2.0",
"query-string": "^4.2.3", "query-string": "^4.2.3",
"random-access-file": "^1.3.0" "random-access-file": "^1.3.0",
"request": "^2.79.0"
} }
} }
function execute_function(context,response){
var job_id = context.jobconfig.job_id;
var transaction_id = context.transaction.id;
var param = context.jobconfig.data_in.param;
var memstore = context.task.memstore
var output_type = 'text'
var data = 'hello world ' + transaction_id;
// memstore.setItem('lasttransaction',transaction_id,function(err){
// response.success(data);
// });
// memstore.getItem('lasttransaction',function(err,value){
// response.success(value);
// });
response.success(data,output_type);
//response.reject();
//response.error("error message")
}
module.exports = execute_function;
var util = require('util');
var DIPlugin = require('../di-plugin');
function DITask(context){
DIPlugin.call(this,context);
this.name = "http-request";
this.output_type = "text";
}
util.inherits(DITask,DIPlugin);
DITask.prototype.execute = require('./execute');
module.exports = DITask;
var request = require('request');
function execute_function(context,response){ function execute_function(context,response){
var job_id = context.jobconfig.job_id; var job_id = context.jobconfig.job_id;
var transaction_id = context.transaction.id; var transaction_id = context.transaction.id;
...@@ -5,9 +7,16 @@ function execute_function(context,response){ ...@@ -5,9 +7,16 @@ function execute_function(context,response){
var memstore = context.task.memstore var memstore = context.task.memstore
var output_type = 'text' var output_type = 'text'
var data = 'hello world ' + transaction_id; var url = param.url;
console.log(url);
request(url, function (error, resp, body) {
if (!error && resp.statusCode == 200) {
response.success(body);
}else{
response.error(error);
}
})
// memstore.setItem('lasttransaction',transaction_id,function(err){ // memstore.setItem('lasttransaction',transaction_id,function(err){
// response.success(data); // response.success(data);
// }); // });
...@@ -17,7 +26,7 @@ function execute_function(context,response){ ...@@ -17,7 +26,7 @@ function execute_function(context,response){
// }); // });
response.success(data,output_type); //response.success(data,output_type);
//response.reject(); //response.reject();
//response.error("error message") //response.error("error message")
......
{ {
"job_id" : "001", "job_id" : "example",
"active" : true, "active" : true,
"trigger" : { "trigger" : {
"type": "cron", "type": "cron",
"cmd": "*/10 * * * *" "cmd": "*/10 * * * * *"
}, },
"data_in" : { "data_in" : {
"type": "http-request", "type": "example",
"param": { "param": {
"url": "http://agritronics.nstda.or.th/ws/get.php" "url": "http://www.google.com"
} }
}, },
"data_out" : { "data_out" : {
......
var schedule = require('node-schedule');
var storage = require('node-persist'); var storage = require('node-persist');
storage.initSync({ storage.initSync({
dir:'db' dir:'db'
}); });
var memstore = require('./lib/memstore'); var memstore = require('./lib/memstore');
var CFG_FILE = "./jobs/testhttp.json"; var CFG_FILE = "./jobs/example.json";
var args = process.argv.slice(2); var args = process.argv.slice(2);
...@@ -13,8 +14,21 @@ if(args.length > 0){ ...@@ -13,8 +14,21 @@ if(args.length > 0){
} }
var jobcfg = require(CFG_FILE); var jobcfg = require(CFG_FILE);
run_job(jobcfg);
if(jobcfg.trigger && jobcfg.trigger.type == 'cron')
{
var triggercfg = jobcfg.trigger;
var cron = jobcfg.trigger.cmd;
console.log('[SCHEDULE MODE]');
console.log('[CRON]\t\t: ' + cron);
var j = schedule.scheduleJob(cron, function(){
run_job(jobcfg);
});
}else{
run_job(jobcfg);
}
...@@ -30,7 +44,7 @@ function run_job(cfg) ...@@ -30,7 +44,7 @@ function run_job(cfg)
"transaction" : transaction "transaction" : transaction
} }
console.log('JOB STARTED \n[TRANSACTION ID]\t: ' + transaction.id + '\n'); console.log('JOB RUNNING \n[TRANSACTION ID]\t: ' + transaction.id + '\n');
//process di //process di
perform_di(context,function(err,resp){ perform_di(context,function(err,resp){
...@@ -47,6 +61,7 @@ function perform_di(context,cb) ...@@ -47,6 +61,7 @@ function perform_di(context,cb)
var jobId = di_context.jobconfig.job_id; var jobId = di_context.jobconfig.job_id;
var di_cfg = di_context.jobconfig.data_in; var di_cfg = di_context.jobconfig.data_in;
console.log('[DI_PLUGIN]\t\t: ' + di_cfg.type);
var DITask = getPlugins('di',di_cfg.type); var DITask = getPlugins('di',di_cfg.type);
var mempref = "ms." + jobId + '.di'; var mempref = "ms." + jobId + '.di';
var diMem = new memstore(mempref,storage); var diMem = new memstore(mempref,storage);
...@@ -56,11 +71,11 @@ function perform_di(context,cb) ...@@ -56,11 +71,11 @@ function perform_di(context,cb)
var di = new DITask(di_context); var di = new DITask(di_context);
di.run(); di.run();
di.on('done',function(response){ di.on('done',function(resp){
console.log('[DI_OUTPUT_TYPE]\t: ' + resp.type); console.log('[DI_OUTPUT_TYPE]\t: ' + resp.type);
console.log('[DI_STATUS]\t\t: ' + resp.status); console.log('[DI_STATUS]\t\t: ' + resp.status);
console.log('>> ' + resp.data); console.log('>>' + resp.data);
cb(null,response); cb(null,resp);
}); });
} }
......
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