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
58311f49
Commit
58311f49
authored
May 09, 2017
by
project
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
fc4aa909
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
0 deletions
+90
-0
job-registry.js
lib/mems/job-registry.js
+18
-0
loadjobs_dir.js
test/loadjobs_dir.js
+72
-0
No files found.
lib/mems/job-registry.js
View file @
58311f49
...
@@ -25,6 +25,24 @@ JobRegistry.prototype.getJob = function(jobid,cb)
...
@@ -25,6 +25,24 @@ JobRegistry.prototype.getJob = function(jobid,cb)
var
jobKey
=
PREFIX
+
':'
+
jobid
;
var
jobKey
=
PREFIX
+
':'
+
jobid
;
this
.
mem
.
get
(
jobKey
,
function
(
err
,
data
){
this
.
mem
.
get
(
jobKey
,
function
(
err
,
data
){
if
(
err
||
!
data
)
{
return
cb
(
err
,
null
);
}
cb
(
err
,
JSON
.
parse
(
data
));
cb
(
err
,
JSON
.
parse
(
data
));
});
});
}
}
JobRegistry
.
prototype
.
setJob
=
function
(
jobid
,
job
,
cb
)
{
var
self
=
this
;
var
jobKey
=
PREFIX
+
':'
+
jobid
;
var
strjob
=
JSON
.
stringify
(
job
);
this
.
mem
.
set
(
jobKey
,
strjob
);
if
(
typeof
cb
==
'function'
){
cb
();
}
}
test/loadjobs_dir.js
0 → 100644
View file @
58311f49
var
fs
=
require
(
'fs'
);
var
redis
=
require
(
'redis'
);
var
ctx
=
require
(
'../context'
);
var
amqp_cfg
=
ctx
.
config
.
amqp
;
var
JobRegistry
=
ctx
.
getLib
(
'lib/mems/job-registry'
);
var
CronList
=
ctx
.
getLib
(
'lib/mems/cronlist'
);
var
jobDir
=
'jobs_dir'
;
//var mem = redis.createClient('redis://localhost:9736/1');
var
mem
=
redis
.
createClient
(
'redis://localhost:6379/1'
);
//var mem = redis.createClient('redis://lab1.igridproject.info:6379/1');
var
job_registry
=
JobRegistry
.
create
({
'redis'
:
mem
});
var
crons
=
CronList
.
create
({
'redis'
:
mem
});
fs
.
readdir
(
jobDir
,
(
err
,
files
)
=>
{
files
.
forEach
(
file
=>
{
addJobFile
(
file
)
});
})
setTimeout
(
function
(){
console
.
log
(
'OK'
);
save
();
},
10000
);
function
addJobFile
(
filename
)
{
var
fpath
=
jobDir
+
'/'
+
filename
;
var
job
=
JSON
.
parse
(
fs
.
readFileSync
(
fpath
,
'utf8'
));
job
=
edit_job
(
job
);
if
(
job
&&
job
.
job_id
&&
job
.
trigger
)
{
console
.
log
(
'add job '
+
job
.
job_id
);
mkJob
(
job
);
mkCronTrigger
(
job
);
}
else
{
console
.
log
(
'ERROR '
+
filename
);
}
}
function
mkJob
(
job
)
{
//console.log(job);
job_registry
.
setJob
(
job
.
job_id
,
job
);
}
function
mkCronTrigger
(
job
)
{
var
jobId
=
job
.
job_id
;
var
cmd
=
job
.
trigger
.
cmd
;
var
cr
=
CronList
.
mkCron
(
jobId
,
cmd
,
jobId
)
crons
.
add
(
cr
);
}
function
save
()
{
crons
.
commit
()
}
function
edit_job
(
job
)
{
eJob
=
job
;
eJob
.
trigger
.
cmd
=
'29,59 * * * *'
;
eJob
.
data_in
.
param
.
url
=
'http://122.155.1.142/ws/get2.php'
;
eJob
.
data_in
.
param
.
init_observed_date
=
'2017-05-01'
;
return
eJob
;
}
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