Authored by lzhy

增加爬取数据开始结束的监听

@@ -9,6 +9,9 @@ const {logger} = require('../libs/logger'); @@ -9,6 +9,9 @@ const {logger} = require('../libs/logger');
9 const {sendMessage} = require('../libs/influx-report'); 9 const {sendMessage} = require('../libs/influx-report');
10 const {getSpecialSizeProducts, getSize} = require('../utils'); 10 const {getSpecialSizeProducts, getSize} = require('../utils');
11 11
  12 +const ddAlert = require('../libs/dingding-alert');
  13 +const moment = require('moment');
  14 +
12 // const {SknRecord} = require('../models'); 15 // const {SknRecord} = require('../models');
13 // const md5 = require('yoho-md5'); 16 // const md5 = require('yoho-md5');
14 17
@@ -21,6 +24,8 @@ const {getSpecialSizeProducts, getSize} = require('../utils'); @@ -21,6 +24,8 @@ const {getSpecialSizeProducts, getSize} = require('../utils');
21 // } 24 // }
22 25
23 module.exports = async(time) => { 26 module.exports = async(time) => {
  27 + const beginTime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  28 + ddAlert(`监控报警 : 爬取毒数据开始 ${beginTime} `, 'bjSpider');
24 const specialSizeProducts = await getSpecialSizeProducts(); 29 const specialSizeProducts = await getSpecialSizeProducts();
25 const sizeData = await mysqlPool.query('select `size_name`,min(`id`) as id from `size` where `size_name` <> \'-\' group by `size_name`'); 30 const sizeData = await mysqlPool.query('select `size_name`,min(`id`) as id from `size` where `size_name` <> \'-\' group by `size_name`');
26 const sizeRelation = {}; 31 const sizeRelation = {};
@@ -47,7 +52,7 @@ module.exports = async(time) => { @@ -47,7 +52,7 @@ module.exports = async(time) => {
47 // } 52 // }
48 53
49 logger.info(`[spiderTask] time: ${time}, product_number: ${sknsData && sknsData.length}`); 54 logger.info(`[spiderTask] time: ${time}, product_number: ${sknsData && sknsData.length}`);
50 - 55 + var n = 0;
51 spider(sknsData.map(p => p.productId), '', {}, 1000) 56 spider(sknsData.map(p => p.productId), '', {}, 1000)
52 .forEach(promise => promise.then(result => { 57 .forEach(promise => promise.then(result => {
53 if (result.status !== 200 && !_.has(result, 'data.detail')) { 58 if (result.status !== 200 && !_.has(result, 'data.detail')) {
@@ -99,5 +104,10 @@ module.exports = async(time) => { @@ -99,5 +104,10 @@ module.exports = async(time) => {
99 }); 104 });
100 } 105 }
101 }); 106 });
  107 + n++;
  108 + if (n == sknsData.length) {
  109 + const endTime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  110 + ddAlert(`监控报警 : 爬取毒数据结束 ${endTime} `, 'bjSpider');
  111 + }
102 })); 112 }));
103 }; 113 };