|
|
|
@ -306,13 +306,12 @@ class HeroUnion {
@@ -306,13 +306,12 @@ class HeroUnion {
|
|
|
|
|
|
|
|
|
|
//定期检查爬虫是否在线
|
|
|
|
|
//如果上一次上报状态时间在10分钟前,则设置该爬虫已下线
|
|
|
|
|
beroHeartCheck() { |
|
|
|
|
heroHeartCheck() { |
|
|
|
|
let _self = this; |
|
|
|
|
|
|
|
|
|
const frequence = 60; //1 分钟检查一次
|
|
|
|
|
const cronjob = cron.schedule(`*/${frequence} * * * * *`, () => { |
|
|
|
|
let timestamp = common.getTimestampInSeconds(); |
|
|
|
|
|
|
|
|
|
_self.heros.forEach(function(item, index) { |
|
|
|
|
if (item.status != 'offline' && timestamp - item.timestamp > _self.heroHeartTimeout) { |
|
|
|
|
_self.heroStatus[item.status] --; |
|
|
|
@ -327,10 +326,27 @@ class HeroUnion {
@@ -327,10 +326,27 @@ class HeroUnion {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
cronjob.start(); |
|
|
|
|
console.log('Cronjob of hero heart check started.'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//自动重新加载配置文件
|
|
|
|
|
autoReloadConfigs() { |
|
|
|
|
let _self = this; |
|
|
|
|
|
|
|
|
|
const frequence = 300; //5 分钟重新加载一次
|
|
|
|
|
const cronjob = cron.schedule(`*/${frequence} * * * * *`, () => { |
|
|
|
|
const forceReload = true; |
|
|
|
|
_self.getConfig(forceReload); |
|
|
|
|
}, { |
|
|
|
|
scheduled: false |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
cronjob.start(); |
|
|
|
|
console.log('Cronjob of config auto reload started.'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取联盟状态
|
|
|
|
|
stats() { |
|
|
|
|
getStats() { |
|
|
|
|
this.stats.taskStatus = this.taskStatus; |
|
|
|
|
this.stats.heroStatus = this.heroStatus; |
|
|
|
|
this.stats.run_seconds = common.getTimestampInSeconds() - this.stats.start_time; |
|
|
|
@ -338,6 +354,13 @@ class HeroUnion {
@@ -338,6 +354,13 @@ class HeroUnion {
|
|
|
|
|
return this.stats; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//初始化
|
|
|
|
|
init() { |
|
|
|
|
this.getConfig(); |
|
|
|
|
this.autoReloadConfigs(); |
|
|
|
|
this.heroHeartCheck(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|