Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
node-bigstream
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bs
node-bigstream
Commits
def4692d
Commit
def4692d
authored
Apr 25, 2017
by
project
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
a9ef971b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
33 deletions
+73
-33
context.js
context.js
+4
-0
jobtask.js
jobworker/lib/jobtask.js
+36
-5
perform.js
plugins/di/di-example/perform.js
+8
-7
test.js
test/test.js
+25
-21
No files found.
context.js
View file @
def4692d
...
...
@@ -16,3 +16,7 @@ module.exports.getPlugins = function(type,name)
return
require
(
path
);
}
module
.
exports
.
sysenv
=
{
}
jobworker/lib/jobtask.js
View file @
def4692d
var
util
=
require
(
'util'
);
var
domain
=
require
(
'domain'
);
var
async
=
require
(
'async'
);
var
domain
=
require
(
'domain'
);
var
crypto
=
require
(
"crypto"
);
var
EventEmitter
=
require
(
'events'
).
EventEmitter
;
var
ctx
=
require
(
'../../context'
);
var
memstore
=
ctx
.
getLib
(
'jobexecutor/lib
/memstore'
);
var
memstore
=
require
(
'.
/memstore'
);
var
bsdata
=
ctx
.
getLib
(
'lib/model/bsdata'
);
module
.
exports
=
JobTask
;
...
...
@@ -12,17 +14,31 @@ function JobTask (prm)
{
EventEmitter
.
call
(
this
);
if
(
!
prm
.
opt
){
prm
.
opt
=
{};}
this
.
handle
=
prm
.
handle
;
this
.
mem
=
prm
.
handle
.
mem
;
this
.
jobcfg
=
prm
.
job_config
;
this
.
input_data
=
prm
.
input_data
;
this
.
transaction_id
=
prm
.
transaction_id
;
this
.
job_timeout
=
prm
.
opt
.
job_timeout
||
3000
;
//0=>IDLE,1=>RUNNING,2=>DONE
this
.
state
=
0
;
};
util
.
inherits
(
JobTask
,
EventEmitter
);
//handle.emit('done',{'status':'error','data':err});
JobTask
.
prototype
.
stop
=
function
(
status
)
{
if
(
this
.
state
==
1
){
this
.
state
=
2
;
this
.
emit
(
'done'
,
status
);
}
}
JobTask
.
prototype
.
run
=
function
()
{
var
self
=
this
;
...
...
@@ -31,6 +47,7 @@ JobTask.prototype.run = function ()
var
job_tr_config
=
this
.
jobcfg
;
var
job_id
=
job_tr_config
.
job_id
;
self
.
state
=
1
;
var
ctx_transaction
=
{
"id"
:
transaction_id
...
...
@@ -80,14 +97,26 @@ JobTask.prototype.run = function ()
});
}
var
jtimeout
=
setTimeout
(
function
(){
self
.
stop
({
'status'
:
'error'
,
'data'
:
'job execution timeout'
});
//self.emit('error',new Error('job execution timeout'))
},
self
.
job_timeout
);
async
.
waterfall
([
task_di
,
task_dt
,
task_do
],
function
(
err
,
resp
)
{
clearTimeout
(
jtimeout
);
if
(
!
err
){
console
.
log
(
'***** JOB SUCCESSFULLY DONE *****'
);
self
.
stop
(
resp
)
//console.log('***** JOB SUCCESSFULLY DONE *****');
}
else
{
console
.
log
(
'***** JOB UNSUCCESSFULLY DONE *****'
);
self
.
stop
(
err
)
//console.log('***** JOB UNSUCCESSFULLY DONE *****');
}
});
}
function
perform_di
(
prm
,
cb
)
...
...
@@ -147,6 +176,7 @@ function perform_do(prm,cb)
var
dout
=
new
DOTask
(
do_context
,
prm
.
request
);
dout
.
run
();
dout
.
on
(
'done'
,
function
(
resp
){
cb
(
null
,
resp
);
});
}
...
...
@@ -159,5 +189,6 @@ function getPlugins(type,name)
function
genTransactionId
()
{
return
"TR"
+
(
new
Date
).
getTime
();
var
id
=
crypto
.
randomBytes
(
3
).
toString
(
"hex"
);
return
"TR"
+
(
new
Date
).
getTime
()
+
id
;
}
plugins/di/di-example/perform.js
View file @
def4692d
...
...
@@ -7,18 +7,19 @@ function perform_function(context,response){
var
output_type
=
'text'
var
data
=
'hello world '
+
transaction_id
;
// memstore.setItem('lasttransaction',transaction_id,function(err){
// response.success(data);
// });
memstore
.
getItem
(
'lasttransaction2'
,
function
(
err
,
value
){
console
.
log
(
'key'
);
console
.
log
(
value
);
response
.
success
(
value
);
});
// memstore.getItem('lasttransaction2',function(err,value){
// console.log('key');
// console.log(value);
// response.success(value);
// });
setTimeout
(
function
(){
response
.
success
(
data
,
output_type
);
},
2000
)
//response.success(data,output_type);
//response.reject();
//response.error("error message")
...
...
test/test.js
View file @
def4692d
...
...
@@ -122,26 +122,26 @@ const crypto = require("crypto");
// console.log(val.t);
// });
//
var redis = require('redis');
// var handle = {'mem' : redis.createClient('redis://:@
bigmaster.igridproject.info:6379/1')}
//
var input_data = {};
//
var job_config = {
//
"job_id" : "example",
//
"active" : true,
//
"trigger" : {
//
"type": "cron",
//
"cmd": "29,59 * * * * *"
//
},
//
"data_in" : {
//
"type": "example"
//
},
//
"data_transform" : {
//
"type": "noop"
//
},
//
"data_out" : {
//
"type": "console"
//
}
//
}
var
redis
=
require
(
'redis'
);
var
handle
=
{
'mem'
:
redis
.
createClient
(
'redis://
bigmaster.igridproject.info:6379/1'
)}
var
input_data
=
{};
var
job_config
=
{
"job_id"
:
"example"
,
"active"
:
true
,
"trigger"
:
{
"type"
:
"cron"
,
"cmd"
:
"29,59 * * * * *"
},
"data_in"
:
{
"type"
:
"example"
},
"data_transform"
:
{
"type"
:
"noop"
},
"data_out"
:
{
"type"
:
"console"
}
}
var
ag
=
{
"job_id"
:
"agritronics-gistda-01"
,
...
...
@@ -191,8 +191,12 @@ var JobTask = ctx.getLib('jobworker/lib/jobtask');
var
job
=
new
JobTask
({
'handle'
:
handle
,
'job_config'
:
job_config
,
'input_data'
:
input_data
'input_data'
:
input_data
,
'opt'
:
{
'job_timeout'
:
30000
}
});
job
.
on
(
'done'
,
function
(
res
){
console
.
log
(
res
);
});
job
.
run
();
// async.reduce([1,2,3], 0, function(memo, item, callback) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment