Browse Source

add data save api call when task is done

master
filesite 8 months ago
parent
commit
e782829210
  1. 34
      spider.mjs

34
spider.mjs

@ -22,6 +22,21 @@ import cron from 'node-cron';
taskMoniter.run(); //监控新任务 taskMoniter.run(); //监控新任务
//HeroUnion英雄联盟对接
let heroUnionConfig = configs.herounion;
let heroBot = new HeroBot(
heroUnionConfig.server_url,
heroUnionConfig.name,
heroUnionConfig.description,
heroUnionConfig.platforms,
heroUnionConfig.contracts,
heroUnionConfig.country,
heroUnionConfig.lang,
heroUnionConfig.contact,
heroUnionConfig.data_mode
);
//配置本地cloud server地址,cloud安装参考:./install_cloud.sh //配置本地cloud server地址,cloud安装参考:./install_cloud.sh
const heroCloudServer = typeof(configs.cloud_server) != 'undefined' && configs.cloud_server ? configs.cloud_server : ''; const heroCloudServer = typeof(configs.cloud_server) != 'undefined' && configs.cloud_server ? configs.cloud_server : '';
@ -65,6 +80,11 @@ import cron from 'node-cron';
&& await tajian.saveDescriptionFiles(task.id, data) && await tajian.saveDescriptionFiles(task.id, data)
) { ) {
taskMoniter.setTaskDone(task.id); taskMoniter.setTaskDone(task.id);
//保存数据到HeroUnion联盟
if (typeof(task.from) != 'undefined' && task.from == 'HeroUnion') {
heroBot.saveTaskData(task.id, task.token, data);
}
}else { }else {
taskMoniter.setTaskFailed(task.id); taskMoniter.setTaskFailed(task.id);
} }
@ -86,20 +106,6 @@ import cron from 'node-cron';
console.log('[%s] Spider started.', common.getTimeString()); console.log('[%s] Spider started.', common.getTimeString());
//HeroUnion英雄联盟对接
let heroUnionConfig = configs.herounion;
let heroBot = new HeroBot(
heroUnionConfig.server_url,
heroUnionConfig.name,
heroUnionConfig.description,
heroUnionConfig.platforms,
heroUnionConfig.contracts,
heroUnionConfig.country,
heroUnionConfig.lang,
heroUnionConfig.contact,
heroUnionConfig.data_mode
);
//爬虫心跳上报 //爬虫心跳上报
const heartBeatFrequence = 5; //5 分钟上报一次 const heartBeatFrequence = 5; //5 分钟上报一次
const heroUnionHeartBeat = cron.schedule(`*/${heartBeatFrequence} * * * *`, async () => { const heroUnionHeartBeat = cron.schedule(`*/${heartBeatFrequence} * * * *`, async () => {

Loading…
Cancel
Save