Commit 56a7ab0f authored by project's avatar project

--no commit message

--no commit message
parent 79bdde61
var request = require('request');
var async = require('async');
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 = 'object/agritronics';
var data = 'hello world';
let result = {
"object_type": 'agritronic',
"station_id": param.station_id,
"data":[]
};
let idx = 0;
//console.log(json_table.length);
async.whilst(function() { return idx < param.data_types.length;}, function(callback) {
let dtype = param.data_types[idx].type;
let node_id = param.data_types[idx].node_id;
let ts = memstore.getItem(`${param.station_id}-${dtype}`);
if(typeof(ts) === 'undefined') ts = `${param.init_observed_date},${param.init_observed_time}`;
let url = param.url + `?appkey=${param.appkey}&p=${param.station_id},${node_id},${dtype},${ts}`;
idx++;
getData(url).then((data) => {
if(data.search("denied") === -1){
result.data.push({
"data_types": dtype,
"value" : data
});
callback();
}
}).catch((err) => {
callback(err);
});
}, function(err) {
if( err ) {
response.error(err);
} else {
//console.log(JSON.stringify(result));
response.success(result, output_type);
}
});
}
function getData(url) {
return new Promise((resolve, reject) => {
request(url, function (error, resp, body) {
if (!error && resp.statusCode == 200) {
resolve(body);
}else{
return reject(error);
}
})
})
}
module.exports = execute_function;
...@@ -8,6 +8,6 @@ function DITask(context){ ...@@ -8,6 +8,6 @@ function DITask(context){
} }
util.inherits(DITask,DIPlugin); util.inherits(DITask,DIPlugin);
DITask.prototype.execute = require('./execute'); DITask.prototype.perform = require('./perform');
module.exports = DITask; module.exports = DITask;
...@@ -8,6 +8,6 @@ function DITask(context){ ...@@ -8,6 +8,6 @@ function DITask(context){
} }
util.inherits(DITask,DIPlugin); util.inherits(DITask,DIPlugin);
DITask.prototype.execute = require('./execute'); DITask.prototype.perform = require('./perform');
module.exports = DITask; module.exports = DITask;
function execute_function(context,response){ function perform_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;
var param = context.jobconfig.data_in.param; var param = context.jobconfig.data_in.param;
...@@ -23,4 +23,4 @@ function execute_function(context,response){ ...@@ -23,4 +23,4 @@ function execute_function(context,response){
} }
module.exports = execute_function; module.exports = perform_function;
...@@ -8,6 +8,6 @@ function DITask(context){ ...@@ -8,6 +8,6 @@ function DITask(context){
} }
util.inherits(DITask,DIPlugin); util.inherits(DITask,DIPlugin);
DITask.prototype.execute = require('./execute'); DITask.prototype.perform = require('./perform');
module.exports = DITask; module.exports = DITask;
...@@ -8,6 +8,6 @@ function DITask(context){ ...@@ -8,6 +8,6 @@ function DITask(context){
} }
util.inherits(DITask,DIPlugin); util.inherits(DITask,DIPlugin);
DITask.prototype.execute = require('./execute'); DITask.prototype.perform = require('./perform');
module.exports = DITask; module.exports = DITask;
...@@ -15,12 +15,12 @@ DIPlugin.prototype.getname = function(){ ...@@ -15,12 +15,12 @@ DIPlugin.prototype.getname = function(){
return this.name; return this.name;
} }
DIPlugin.prototype.execute = function(){} DIPlugin.prototype.perform = function(){}
DIPlugin.prototype.run = function(){ DIPlugin.prototype.run = function(){
this.emit('start'); this.emit('start');
var resp = new DIResponse(this); var resp = new DIResponse(this);
this.execute(this.jobcontext,resp); this.perform(this.jobcontext,resp);
} }
module.exports = DIPlugin; module.exports = DIPlugin;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"data_out" : { "data_out" : {
"type": "dir", "type": "dir",
"param": { "param": {
"path" : "D:/testfile" "path" : "D:/testdata"
} }
} }
} }
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