Authored by 郝肖肖

'task'

@@ -145,6 +145,7 @@ public/bundle/* @@ -145,6 +145,7 @@ public/bundle/*
145 .DS_Store 145 .DS_Store
146 .devhost 146 .devhost
147 library 147 library
  148 +yarn.lock
148 149
149 150
150 ### foreman ### 151 ### foreman ###
@@ -50,16 +50,6 @@ app.get('/synchronousKeywords', seo.synchronousKeywords); @@ -50,16 +50,6 @@ app.get('/synchronousKeywords', seo.synchronousKeywords);
50 app.get('/sendKeywordsUrls', seo.sendKeywordsUrls); 50 app.get('/sendKeywordsUrls', seo.sendKeywordsUrls);
51 app.get('/sendUrls', seo.sendUrls); 51 app.get('/sendUrls', seo.sendUrls);
52 52
53 -// 404错误  
54 -app.use(function(req, res) {  
55 - return res.status(404).send('');  
56 -});  
57 -  
58 -// 500错误  
59 -app.use(function(err, req, res) {  
60 - return res.status(err.status || 500).send('');  
61 -});  
62 -  
63 app.listen(config.port, function() { 53 app.listen(config.port, function() {
64 logger.info(`yoho seo start : http://127.0.0.1:${config.port}`); 54 logger.info(`yoho seo start : http://127.0.0.1:${config.port}`);
65 }); 55 });
@@ -2,21 +2,33 @@ @@ -2,21 +2,33 @@
2 const SeoIndexModel = require('../../models/seo/index'); 2 const SeoIndexModel = require('../../models/seo/index');
3 3
4 const index = (req, res) => { 4 const index = (req, res) => {
5 - return req.ctx(SeoIndexModel).writerGoodsXml(req.params).then(result => {  
6 - return res.json(result); 5 + if (global.IS_GOODS_XML_RUN) {
  6 + return res.json({code: 201, message: '上一个任务正在运行中...'});
  7 + }
  8 +
  9 + global.IS_GOODS_XML_RUN = true;
  10 +
  11 + req.ctx(SeoIndexModel).writerGoodsXml(req.params).then(() => {
  12 + global.IS_GOODS_XML_RUN = false;
  13 + });
  14 +
  15 + return res.json({
  16 + code: 200,
  17 + data: `http://spiderwebhook.yoho.cn/dist/goods-xml/goods-${req.params.start || 1}.xml`,
  18 + message: '任务创建成功,开始运行...'
7 }); 19 });
8 }; 20 };
9 21
10 const autoGoodsXml = (req, res) => { 22 const autoGoodsXml = (req, res) => {
11 if (global.IS_GOODS_XML_RUN) { 23 if (global.IS_GOODS_XML_RUN) {
12 - return res.json({code: 201, message: '后台正在运行中...'}); 24 + return res.json({code: 201, message: '上一个任务正在运行中...'});
13 } 25 }
14 26
15 global.IS_GOODS_XML_RUN = true; 27 global.IS_GOODS_XML_RUN = true;
16 28
17 req.ctx(SeoIndexModel).autoGoodsXml({start: 1}); 29 req.ctx(SeoIndexModel).autoGoodsXml({start: 1});
18 30
19 - res.json({code: 200, message: 'success...'}); 31 + res.json({code: 200, message: '任务创建成功,开始运行...'});
20 }; 32 };
21 33
22 const setTask = (req, res) => { 34 const setTask = (req, res) => {
@@ -10,6 +10,7 @@ const goodsHbs = require(`${ROOT_PATH}/hbs/partials/seo/index.hbs`); @@ -10,6 +10,7 @@ const goodsHbs = require(`${ROOT_PATH}/hbs/partials/seo/index.hbs`);
10 const util = require(`${ROOT_PATH}/libs/util`); 10 const util = require(`${ROOT_PATH}/libs/util`);
11 const redis = require(`${ROOT_PATH}/libs/redis`); 11 const redis = require(`${ROOT_PATH}/libs/redis`);
12 const SIZE = 4000; 12 const SIZE = 4000;
  13 +const GOODS_URL = 'http://spiderwebhook.yoho.cn/dist/goods-xml';
13 14
14 class SeoIndexModel extends global.yoho.BaseModel { 15 class SeoIndexModel extends global.yoho.BaseModel {
15 constructor(ctx) { 16 constructor(ctx) {
@@ -38,7 +39,8 @@ class SeoIndexModel extends global.yoho.BaseModel { @@ -38,7 +39,8 @@ class SeoIndexModel extends global.yoho.BaseModel {
38 39
39 result = []; 40 result = [];
40 41
41 - return {code: 200, data: `http://127.0.0.1:6005/dist/goods-xml/${fileName}`}; 42 + console.log(`${GOODS_URL}/${fileName} over...`);
  43 + return {code: 200, data: `${GOODS_URL}/${fileName}`};
42 }); 44 });
43 } 45 }
44 46
@@ -63,7 +65,7 @@ class SeoIndexModel extends global.yoho.BaseModel { @@ -63,7 +65,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
63 65
64 _.each(item.goods_list, goods => { 66 _.each(item.goods_list, goods => {
65 images.push({ 67 images.push({
66 - contentUrl: helpers.image(goods.images_url, 450, 600), 68 + contentUrl: `https:${helpers.image(goods.images_url, 450, 600)}`,
67 height: 600, 69 height: 600,
68 width: 450, 70 width: 450,
69 description: `${item.product_name}-${goods.color_name}`, 71 description: `${item.product_name}-${goods.color_name}`,
@@ -73,7 +75,7 @@ class SeoIndexModel extends global.yoho.BaseModel { @@ -73,7 +75,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
73 }); 75 });
74 76
75 products.push({ 77 products.push({
76 - loc: `http://spiderwebhook.yoho.cn/dist/goods-xml/goods-${params.start}.xml`, 78 + loc: `${GOODS_URL}/goods-${params.start}.xml`,
77 lastmod: moment.unix(item.edit_time).format('YYYY-MM-DD'), 79 lastmod: moment.unix(item.edit_time).format('YYYY-MM-DD'),
78 changefreq: 'weekly', 80 changefreq: 'weekly',
79 priority: 1.0, 81 priority: 1.0,
@@ -138,12 +140,12 @@ class SeoIndexModel extends global.yoho.BaseModel { @@ -138,12 +140,12 @@ class SeoIndexModel extends global.yoho.BaseModel {
138 140
139 searchList(params) { 141 searchList(params) {
140 params = _.assign({ 142 params = _.assign({
141 - limit: 60, 143 + limit: 100,
  144 + method: 'app.search.li',
142 status: 1, 145 status: 1,
143 - sales: 'Y',  
144 stocknumber: 1, 146 stocknumber: 1,
145 - method: 'app.search.li',  
146 - attribute_not: 2 147 + attribute_not: 2,
  148 + udid: 'seo_format_data'
147 }, params); 149 }, params);
148 150
149 return this.get({ 151 return this.get({
@@ -77,20 +77,15 @@ module.exports = { @@ -77,20 +77,15 @@ module.exports = {
77 maxFiles: 7 77 maxFiles: 7
78 }, 78 },
79 errorFile: { 79 errorFile: {
  80 + close: false,
80 name: 'error', 81 name: 'error',
81 level: 'error', 82 level: 'error',
82 filename: 'logs/error.log', 83 filename: 'logs/error.log',
83 handleExceptions: true, 84 handleExceptions: true,
84 maxFiles: 7 85 maxFiles: 7
85 }, 86 },
86 - udp: { // send by udp  
87 - measurement: 'yohobuy_node_log',  
88 - level: 'debug', // logger level  
89 - host: 'influxdblog.web.yohoops.org', // influxdb host  
90 - port: '4444' // influxdb port  
91 - },  
92 console: { 87 console: {
93 - level: 'info', 88 + level: 'debug',
94 colorize: 'all', 89 colorize: 'all',
95 prettyPrint: true 90 prettyPrint: true
96 } 91 }
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <fromSrc>{{fromSrc}}</fromSrc> 11 <fromSrc>{{fromSrc}}</fromSrc>
12 {{#images}} 12 {{#images}}
13 <image> 13 <image>
14 - <contentUrl>{{contentUrl}}</contentUrl> 14 + <contentUrl><![CDATA[{{{contentUrl}}}]]></contentUrl>
15 <height>{{height}}</height> 15 <height>{{height}}</height>
16 <width>{{width}}</width> 16 <width>{{width}}</width>
17 <description>{{description}}</description> 17 <description>{{description}}</description>
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 "winston": "^2.3.1", 32 "winston": "^2.3.1",
33 "winston-daily-rotate-file": "^1.1.1", 33 "winston-daily-rotate-file": "^1.1.1",
34 "yoho-md5": "^2.0.0", 34 "yoho-md5": "^2.0.0",
35 - "yoho-node-lib": "^0.2.23" 35 + "yoho-node-lib": "=0.5.29"
36 }, 36 },
37 "devDependencies": { 37 "devDependencies": {
38 "eslint": "^2.12.0", 38 "eslint": "^2.12.0",