Authored by lzhy

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

... ... @@ -9,6 +9,9 @@ const {logger} = require('../libs/logger');
const {sendMessage} = require('../libs/influx-report');
const {getSpecialSizeProducts, getSize} = require('../utils');
const ddAlert = require('../libs/dingding-alert');
const moment = require('moment');
// const {SknRecord} = require('../models');
// const md5 = require('yoho-md5');
... ... @@ -21,6 +24,8 @@ const {getSpecialSizeProducts, getSize} = require('../utils');
// }
module.exports = async(time) => {
const beginTime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
ddAlert(`监控报警 : 爬取毒数据开始 ${beginTime} `, 'bjSpider');
const specialSizeProducts = await getSpecialSizeProducts();
const sizeData = await mysqlPool.query('select `size_name`,min(`id`) as id from `size` where `size_name` <> \'-\' group by `size_name`');
const sizeRelation = {};
... ... @@ -47,7 +52,7 @@ module.exports = async(time) => {
// }
logger.info(`[spiderTask] time: ${time}, product_number: ${sknsData && sknsData.length}`);
var n = 0;
spider(sknsData.map(p => p.productId), '', {}, 1000)
.forEach(promise => promise.then(result => {
if (result.status !== 200 && !_.has(result, 'data.detail')) {
... ... @@ -99,5 +104,10 @@ module.exports = async(time) => {
});
}
});
n++;
if (n == sknsData.length) {
const endTime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
ddAlert(`监控报警 : 爬取毒数据结束 ${endTime} `, 'bjSpider');
}
}));
};
... ...