From e7828292105a7bb1c797543ef384c3ed7ee2e620 Mon Sep 17 00:00:00 2001 From: filesite Date: Sat, 13 Apr 2024 12:24:11 +0800 Subject: [PATCH] add data save api call when task is done --- spider.mjs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/spider.mjs b/spider.mjs index ab999eb..b63e4bd 100644 --- a/spider.mjs +++ b/spider.mjs @@ -22,6 +22,21 @@ import cron from 'node-cron'; 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 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) ) { taskMoniter.setTaskDone(task.id); + + //保存数据到HeroUnion联盟 + if (typeof(task.from) != 'undefined' && task.from == 'HeroUnion') { + heroBot.saveTaskData(task.id, task.token, data); + } }else { taskMoniter.setTaskFailed(task.id); } @@ -86,20 +106,6 @@ import cron from 'node-cron'; 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 heroUnionHeartBeat = cron.schedule(`*/${heartBeatFrequence} * * * *`, async () => {