Authored by 陈峰

commit

... ... @@ -8,7 +8,7 @@ const spiderTask = require('./tasks/spider-task');
const calvAvgTask = require('./tasks/calc-task');
const clearTask = require('./tasks/clear-task');
const priceTask = require('./tasks/price-task');
// const priceLineTask = require('./tasks/price-line-task');
const priceLineTask = require('./tasks/price-line-task');
global.isProduction = process.env.NODE_ENV === 'production';
global.sender = new Sender(config.monitorReport); // 初始化数据上报
... ... @@ -33,7 +33,7 @@ schedule.scheduleJob('0 10 1 * * *', () => {
priceTask();
});
// priceLineTask.forEach(taskInfo => {
// schedule.scheduleJob(taskInfo.cron, taskInfo.task);
// });
priceLineTask.forEach(taskInfo => {
schedule.scheduleJob(taskInfo.cron, taskInfo.task);
});
... ...
... ... @@ -35,5 +35,3 @@ module.exports = async() => {
logger.error(`[price-line-clear-task]删除数据错误, error: ${error.stack}`);
}
};
module.exports();
... ...
... ... @@ -44,9 +44,7 @@ module.exports = async() => {
};
});
logger.info(`[price-line-task] incre-relation ${newRelations.length}`);
logger.info(`[incre-relation-task] incre-relation ${newRelations.length}`);
await ProductRelationModel.insert(...newRelations);
};
module.exports();
... ...
... ... @@ -12,9 +12,18 @@ module.exports = async() => {
const halfYearTime = _.first(least180Day).create_time;
if (halfYearTime && insertTime.diff(dayjs(halfYearTime * 1000), 'day') < 3) {
logger.info(`[price-180day-task] skip date: ${insertTime.unix()}`);
return;
}
}
const resultExists = await mysqlPool.query('SELECT COUNT(*) AS Num FROM `price_trend_half_year` WHERE `create_time` = :createTime', {
createTime: insertTime.unix()
});
if (_.first(resultExists).Num > 0) {
logger.info(`[price-180day-task] exists createtime price: ${insertTime.unix()}`);
return;
}
if (leastDay.length) {
const dayTime = _.first(leastDay).create_time;
... ... @@ -24,8 +33,7 @@ module.exports = async() => {
insertTime: insertTime.unix()
});
logger.info(`[price-line-task] 180day insert ${affectedRows}`);
logger.info(`[price-180day-task] insert ${affectedRows}`);
}
}
};
module.exports();
\ No newline at end of file
... ...
... ... @@ -13,7 +13,14 @@ module.exports = async() => {
insertTime = now.startOf('day');
}
const leastDay = await mysqlPool.query('SELECT MAX(`create_time`) AS create_time FROM `price_trend_day`');
const resultExists = await mysqlPool.query('SELECT COUNT(*) AS Num FROM `price_trend_month` WHERE `create_time` = :createTime', {
createTime: insertTime.unix()
});
if (_.first(resultExists).Num > 0) {
logger.info(`[price-30day-task] exists createtime price: ${insertTime.unix()}`);
return;
}
if (leastDay.length) {
const dayTime = _.first(leastDay).create_time;
... ... @@ -23,8 +30,7 @@ module.exports = async() => {
insertTime: insertTime.unix()
});
logger.info(`[price-line-task] 30day insert ${affectedRows}`);
logger.info(`[price-30day-task] insert ${affectedRows}`);
}
}
};
module.exports();
\ No newline at end of file
... ...
... ... @@ -6,7 +6,14 @@ const {logger} = require('../../libs/logger');
module.exports = async() => {
const insertTime = dayjs().startOf('day').unix();
const leastDay = await mysqlPool.query('SELECT MAX(`create_time`) AS create_time FROM `price_trend_day`');
const resultExists = await mysqlPool.query('SELECT COUNT(*) AS Num FROM `price_trend_sixty_day` WHERE `create_time` = :createTime', {
createTime: insertTime
});
if (_.first(resultExists).Num > 0) {
logger.info(`[price-60day-task] exists createtime price: ${insertTime}`);
return;
}
if (leastDay.length) {
const dayTime = _.first(leastDay).create_time;
... ... @@ -16,8 +23,7 @@ module.exports = async() => {
insertTime
});
logger.info(`[price-line-task] 60day insert ${affectedRows}`);
logger.info(`[price-60day-task] insert ${affectedRows}`);
}
}
};
module.exports();
\ No newline at end of file
... ...
... ... @@ -78,6 +78,8 @@ const task = async({productId, productCode, third}) => {
if (sizeRelation[size]) {
const price = calcPrice(skusGroups[size]);
logger.info(`[price-day-task] skusGroups: ${JSON.stringify(skusGroups[size])}, price: ${price}`);
if (price > 0) {
return {
size,
... ... @@ -90,11 +92,11 @@ const task = async({productId, productCode, third}) => {
return {
productId,
price: Math.round(_.sumBy(_.filter(skus, s => s.price > 0), 'price') / skus.length) || 0,
price: Math.round(_.sumBy(skus, 'price') / skus.length) || 0,
skus,
};
} catch (error) {
logger.error(`[price-line-task], ${error}`);
logger.error(`[price-day-task] dayTask, ${error}`);
}
};
... ... @@ -110,15 +112,25 @@ const report = (product, time) => {
if (result) {
logger.info(`[price-line-task] insert success productId: ${product.productId}, sizeId: ${sku.sizeId}, price: ${sku.price}, sknPrice: ${product.price}, time: ${time}`);
logger.info(`[price-day-task] dayTask, insert success productId: ${product.productId}, sizeId: ${sku.sizeId}, price: ${sku.price}, sknPrice: ${product.price}, time: ${time}`);
} else {
logger.error(`[price-line-task] insert fail productId: ${product.productId}, sizeId: ${sku.sizeId}, price: ${sku.price}, sknPrice: ${product.price}, time: ${time}`);
logger.error(`[price-day-task] dayTask, insert fail productId: ${product.productId}, sizeId: ${sku.sizeId}, price: ${sku.price}, sknPrice: ${product.price}, time: ${time}`);
}
});
};
module.exports = async() => {
const now = dayjs().startOf('hour').unix();
const resultExists = await mysqlPool.query('SELECT COUNT(*) AS Num FROM `price_trend_day` WHERE `create_time` = :createTime', {
createTime: now
});
if (_.first(resultExists).Num > 0) {
logger.info(`[price-day-task] dayTask, exists createtime price: ${now}`);
return;
}
const lockTask = lockup(task);
const products = await ProductRelationModel.findAll();
... ... @@ -128,4 +140,3 @@ module.exports = async() => {
report(result, now);
});
};
module.exports();
\ No newline at end of file
... ...
... ... @@ -25,8 +25,17 @@ const task = async result => {
const locktask = lockup(task, 50);
let open = false;
let inx = 0;
ProductRelationModel.findAll().then((results) => {
results.forEach(async result => {
locktask(result);
if (result.productId === 10000853) {
open = true;
}
if (open && inx < 300) {
locktask(result);
inx++;
}
});
});
... ...