-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
46 lines (45 loc) · 1.62 KB
/
config.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
var config_read = require('./config_read');
var crawler = require('./lib/crawler');
var setup = exports.setup = function(filename, tasks, tacticsHandler, strategyManager){
var tactics = [];
var strategy = [];
var config = {};
tasks.push(function config_ini_read(next){
config_read.readApp(filename, function(err, _config){
config = _config;
Object.keys(config.requestlimit).forEach(function(key){
var waittime = config.requestlimit[key][0];
var count = config.requestlimit[key][1];
console.log('setup requestlimit host[%s],wait[%d],count[%d]', key, waittime, count);
crawler.limitTable.set(key, count, waittime);
});
Object.keys(config.commander).forEach(function(key){
switch(key){
case 'tacticsdir':
tactics = config.commander[key];
break;
case 'strategydir':
strategy = config.commander[key];
break;
}
});
next(err);
});
});
tasks.push(function config_phase1_initialize(next){
tacticsHandler.addDir(tactics);
tacticsHandler.initialize(function(err){
next(err);
});
});
tasks.push(function config_phase2_initialize(next){
strategyManager.addDir(strategy);
strategyManager.initialize(tacticsHandler, config, function(err){
next(err);
});
});
tasks.push(function task_initialize(next){
strategyManager.run();
next(null);
});
}