-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
51 lines (39 loc) · 1.02 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
var args = process.argv.slice(2);
if(args[0] === '--create') {
var jobs = require('./index').init('redis://localhost:6379/0');
var log = function(data) {console.log(data); };
var createJobs = function() {
for(var i = 0; i < 20; ++i) {
var job = jobs.create('job-type1',{
value: '123',
value2: '234'
});
job.on('update',log);
job.on('complete',log);
job.on('error',function(data) {
console.error(data);
})
}
};
createJobs();
setInterval(createJobs,5000);
} else if (args[0] === '--web') {
if(args[1]) {
var jobs = require('./index').init(args[1]);
} else {
var jobs = require('./index').init('redis://localhost:6379/0');
}
jobs.startServer(8888);
} else {
jobs.process('job-type1',2,function(job,callback) {
if(!job) {
return console.log('no job');
}
console.log('Processing job: ' + job.id);
job.update(job.id + ': this is a job update!');
job.complete('yay done');
job.error('some error happened');
callback(null,'someoutput','this is my result');
});
}