Authored by 郝肖肖

'goods-xml-task'

... ... @@ -8,6 +8,11 @@ const index = (req, res) => {
};
const autoGoodsXml = (req, res) => {
if (global.IS_GOODS_XML_RUN) {
return res.json({code: 201, message: '后台正在运行中...'});
}
global.IS_GOODS_XML_RUN = true;
req.ctx(SeoIndexModel).autoGoodsXml({start: 1});
... ...
... ... @@ -32,6 +32,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
const fWrite = fs.createWriteStream(`${ROOT_PATH}/public/dist/${fileName}`);
fWrite.write(goodsHbs({products: result}).replace(/\s+/g, ' '));// max 9.5M
fWrite.end();
result = [];
... ... @@ -161,6 +162,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
console.log(`autoGoodsXml: params: ${JSON.stringify(params)}`);
if (rdata.code !== 200) {
global.IS_GOODS_XML_RUN = false;
return {};
}
... ... @@ -169,14 +171,14 @@ class SeoIndexModel extends global.yoho.BaseModel {
}
setTask(params) {
return redis.hset('global:yoho:seo:task', md5(params.url), JSON.stringify({
return redis.hsetAsync('global:yoho:seo:task', md5(params.url), JSON.stringify({
url: params.url,
time: params.time || 1000
}));
}
delTask(url) {
return redis.hdel('global:yoho:seo:task', md5(url));
return redis.hdelAsync('global:yoho:seo:task', md5(url));
}
}
... ...
... ... @@ -13,7 +13,7 @@ const SeoTask = {
return redis.hvalsAsync('global:yoho:seo:task').then(urls => {
console.log(`SeoTask urls: ${urls}, exec...`);
urls.each((item) => {
urls.forEach((item) => {
item = JSON.parse(item || '[]');
this.execTask(item.url, item.time);
});
... ...