-
Notifications
You must be signed in to change notification settings - Fork 1
/
tplScript.js
53 lines (49 loc) · 1.07 KB
/
tplScript.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
52
53
publish = function(topic,data,err){
let obj = {}
if(!data) data = {}
if(err) obj.error = true
obj.topic = topic
obj.data = data
process.send(JSON.stringify(obj))
}
process.on('SIGINT', function () {
publish("aborted")
process.exit(2);
});
process.on('uncaughtException', function(e) {
publish("error",e.stack)
console.log('Uncaught Exception...');
console.log(e.stack);
process.exit(99);
});
function Paijem(){
this.tag = ""
this.log = function(){
let serializeArgv = ""
for(let x in arguments) {serializeArgv=serializeArgv+arguments[x]+" "}
process.stdout.write("["+this.tag+"] "+serializeArgv+"\n")
}
this.finish = function(data){
publish("finish",data)
process.exit()
}
this.error = function(data){
publish("finish",data,true)
process.exit()
}
this.pub = publish
this.sub = function(topic,fn){
process.on('message', message => {
obj = JSON.parse(message)
if(topic == obj.topic) fn(obj.data)
})
}
}
$ = new Paijem()
//here
argv = {}
argvStr = process.argv[2]
if(argvStr!=""){
argv = JSON.parse(argvStr)
}
job(argv)