forked from nkchwfree/netgen-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
66 lines (51 loc) · 1.47 KB
/
Copy pathmain.js
File metadata and controls
66 lines (51 loc) · 1.47 KB
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
54
55
56
57
58
59
60
61
62
63
64
var config = require('./config/config').config;
var log = require('./lib/log');
var Parser = require('./lib/parser').Parser;
var parser = new Parser( config.worker_number );
var hook = require('devent').createDEvent('convertor');
parser.on('task-finished', function(task){
try {
log.log('finish task: '+ task.uri);
hook.emit('task-finished', task);
}
catch(e) {
log.debug('Task Finished Error.');
log.debug(e);
}
});
var report_task_error = function(error, task) {
try {
log.log('report task error: '+error+' '+ task.uri);
hook.emit('task-error', task);
}
catch(e) {
log.debug('Task-Error Error.');
log.debug(e);
}
}
parser.on('tidy-error', report_task_error);
parser.on('uri-error', report_task_error);
//³¬¹ýÖØÊÔ´ÎÊý
parser.on('retry_too_many_times', function(error, task){
log.log('finish error task after try '+ task.retry +'times.');
hook.emit('task-finished', task);
});
parser.on('no-page-content', function(error, task){
log.log('no-page-content,finish task.'+task.uri);
hook.emit('task-finished', task);
});
hook.on('queued', function( queue ){
//log.debug(queue);
if(queue=='page_content') {
//log.debug('emit event.');
parser.emit('has-task');
}
});
process.on('uncaughtException', function(e){
console.log(['uncaughtException:', e]);
});
var func = function(){
parser.emit('has-task');
setTimeout(func, config.interval);
}
func();