Authored by 郝肖肖

'goods-xml-task'

@@ -8,6 +8,11 @@ const index = (req, res) => { @@ -8,6 +8,11 @@ const index = (req, res) => {
8 }; 8 };
9 9
10 const autoGoodsXml = (req, res) => { 10 const autoGoodsXml = (req, res) => {
  11 + if (global.IS_GOODS_XML_RUN) {
  12 + return res.json({code: 201, message: '后台正在运行中...'});
  13 + }
  14 +
  15 + global.IS_GOODS_XML_RUN = true;
11 16
12 req.ctx(SeoIndexModel).autoGoodsXml({start: 1}); 17 req.ctx(SeoIndexModel).autoGoodsXml({start: 1});
13 18
@@ -32,6 +32,7 @@ class SeoIndexModel extends global.yoho.BaseModel { @@ -32,6 +32,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
32 const fWrite = fs.createWriteStream(`${ROOT_PATH}/public/dist/${fileName}`); 32 const fWrite = fs.createWriteStream(`${ROOT_PATH}/public/dist/${fileName}`);
33 33
34 fWrite.write(goodsHbs({products: result}).replace(/\s+/g, ' '));// max 9.5M 34 fWrite.write(goodsHbs({products: result}).replace(/\s+/g, ' '));// max 9.5M
  35 + fWrite.end();
35 36
36 result = []; 37 result = [];
37 38
@@ -161,6 +162,7 @@ class SeoIndexModel extends global.yoho.BaseModel { @@ -161,6 +162,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
161 console.log(`autoGoodsXml: params: ${JSON.stringify(params)}`); 162 console.log(`autoGoodsXml: params: ${JSON.stringify(params)}`);
162 163
163 if (rdata.code !== 200) { 164 if (rdata.code !== 200) {
  165 + global.IS_GOODS_XML_RUN = false;
164 return {}; 166 return {};
165 } 167 }
166 168
@@ -169,14 +171,14 @@ class SeoIndexModel extends global.yoho.BaseModel { @@ -169,14 +171,14 @@ class SeoIndexModel extends global.yoho.BaseModel {
169 } 171 }
170 172
171 setTask(params) { 173 setTask(params) {
172 - return redis.hset('global:yoho:seo:task', md5(params.url), JSON.stringify({ 174 + return redis.hsetAsync('global:yoho:seo:task', md5(params.url), JSON.stringify({
173 url: params.url, 175 url: params.url,
174 time: params.time || 1000 176 time: params.time || 1000
175 })); 177 }));
176 } 178 }
177 179
178 delTask(url) { 180 delTask(url) {
179 - return redis.hdel('global:yoho:seo:task', md5(url)); 181 + return redis.hdelAsync('global:yoho:seo:task', md5(url));
180 } 182 }
181 } 183 }
182 184
@@ -13,7 +13,7 @@ const SeoTask = { @@ -13,7 +13,7 @@ const SeoTask = {
13 return redis.hvalsAsync('global:yoho:seo:task').then(urls => { 13 return redis.hvalsAsync('global:yoho:seo:task').then(urls => {
14 console.log(`SeoTask urls: ${urls}, exec...`); 14 console.log(`SeoTask urls: ${urls}, exec...`);
15 15
16 - urls.each((item) => { 16 + urls.forEach((item) => {
17 item = JSON.parse(item || '[]'); 17 item = JSON.parse(item || '[]');
18 this.execTask(item.url, item.time); 18 this.execTask(item.url, item.time);
19 }); 19 });