Commit 688c99ee authored by project's avatar project

--no commit message

--no commit message
parent a82ed16d
function execute_function(ctx,out){ function execute_function(context,response){
// var job_id = ctx.profile.jobid; // var job_id = context.profile.job_id;
// var transaction_id = ctx.profile.transaction_id; // var transaction_id = context.profile.transaction_id;
// var param = ctx.parameter; // var param = ctx.parameter;
var data = ''; var data = 'hello world';
setTimeout(function () {
response.success(context.jobid + ' ' + data);
}, 1000);
console.log(this.getname() + 'plug-ins');
//response.cancel();
//response.error("error message")
//response.success(data);
} }
module.exports = execute_function; module.exports = execute_function;
var util = require('util'); var util = require('util');
var DIPlugin = require('../di-plugin'); var DIPlugin = require('../di-plugin');
function DITask(){ function DITask(context){
DIPlugin.call(this,context);
this.name = "http" this.name = "http"
} }
util.inherits(DITask,DIPlugin); util.inherits(DITask,DIPlugin);
......
var util = require('util'); var util = require('util');
var EventEmitter = require('events'); var EventEmitter = require('events').EventEmitter;
function DIPlugin(context){
EventEmitter.call(this);
function DIPlugin(){
this.name = 'base'; this.name = 'base';
this.jobcontext = context;
this.outputdata = null;
} }
util.inherits(DIPlugin, EventEmitter); util.inherits(DIPlugin, EventEmitter);
...@@ -10,6 +14,37 @@ DIPlugin.prototype.getname = function(){ ...@@ -10,6 +14,37 @@ DIPlugin.prototype.getname = function(){
return this.name; return this.name;
} }
DIPlugin.prototype.execute = function(){}
DIPlugin.prototype.run = function(){
this.emit('start');
var resp = new DIResponse(this);
this.execute(this.jobcontext,resp);
}
module.exports = DIPlugin; module.exports = DIPlugin;
/*
DIResponse
*/
function DIResponse(handle){
this.handle = handle;
}
DIResponse.prototype.success = function(data){
this.handle.emit('done',response('success',data));
}
DIResponse.prototype.error = function(err){
this.handle.emit('done',response('error',data));
}
DIResponse.prototype.cancel = function(){
this.handle.emit('done',response('cancel',null));
}
function response(status,data){
return {'status':status,'data':data}
}
var DITask = require('../plugins/di/di-http-request'); var DITask = require('../plugins/di/di-http-request');
var di = new DITask(); var di = new DITask({jobid:'j01'});
di.execute(); di.run();
di.on('done',function(response){
console.log('>> ' + response.data);
})
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