Authored by 郝肖肖

'task-log'

... ... @@ -4,7 +4,6 @@ const ROOT_PATH = global.ROOT_PATH;
const _ = require('lodash');
const redis = require(`${ROOT_PATH}/libs/redis`);
const YohoApiModel = require('./../interface/yoho-api');
const TaskLogModel = require('./../interface/task-log');
const co = Promise.coroutine;
const rp = require('request-promise');
const senUrl = 'http://data.zz.baidu.com/urls';
... ... @@ -18,7 +17,6 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
super(ctx);
this.yohoApiModel = new YohoApiModel(ctx);
this.taskLogModel = new TaskLogModel(ctx);
}
// 向百度发送数据
... ... @@ -115,18 +113,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
return rdata;
})().then(rdata => {
let key = this.taskLogModel.getKey('http://127.0.0.1:6005/goodsUrl');
return this.taskLogModel.ltrim(key).then(() => {
return Promise.all([
this.taskLogModel.add(key, rdata[0]),
this.taskLogModel.add(key, rdata[1])
]);
}).then(() => {
return rdata;
});
});
})();
}
// 提交逛详情URL
... ... @@ -194,18 +181,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
Object.assign(rdata[1], {message: `WAP: ${message}`});
return rdata;
})().then(rdata => {
let key = this.taskLogModel.getKey('http://127.0.0.1:6005/guangUrl');
return this.taskLogModel.ltrim(key).then(() => {
return Promise.all([
this.taskLogModel.add(key, rdata[0]),
this.taskLogModel.add(key, rdata[1])
]);
}).then(() => {
return rdata;
});
});
})();
}
}
... ...
... ... @@ -6,7 +6,6 @@ const co = Promise.coroutine;
const rp = require('request-promise');
const redis = require(`${ROOT_PATH}/libs/redis`);
const YohoApiModel = require('./../interface/yoho-api');
const TaskLogModel = require('./../interface/task-log');
const senUrl = 'http://data.zz.baidu.com/urls?appid=1583402501013173&token=K0L5PUhk1XOko81r&type=';
// http://ziyuan.baidu.com/xzh/commit/push?appid=1583402501013173&qq-pf-to=pcqq.c2c
... ... @@ -16,7 +15,6 @@ class XzhIndexModel extends global.yoho.BaseModel {
super(ctx);
this.yohoApiModel = new YohoApiModel(ctx);
this.taskLogModel = new TaskLogModel(ctx);
}
index() {
... ... @@ -65,15 +63,7 @@ class XzhIndexModel extends global.yoho.BaseModel {
tids = [];
return Object.assign(rdata, {message: message});
})().then(rdata => {
let key = this.taskLogModel.getKey('http://127.0.0.1:6005/sendXzh');
return this.taskLogModel.ltrim(key).then(() => {
return this.taskLogModel.add(key, rdata);
}).then(() => {
return rdata;
});
});
})();
}
// 向百度发送数据
... ...
... ... @@ -2,12 +2,15 @@
const ROOT_PATH = global.ROOT_PATH;
const os = require('os');
const _ = require('lodash');
const util = require(`${ROOT_PATH}/libs/util`);
const schedule = require('node-schedule');
const rp = require('request-promise');
const redis = require(`${ROOT_PATH}/libs/redis`);
const config = require(`${ROOT_PATH}/config/config`);
const jobTask = config.jobTask;
const md5 = require('yoho-md5');
const TASK_KEY_LOG = 'global:yoho:task:log';
const SeoTask = {
intHandle() {
... ... @@ -39,13 +42,27 @@ const SeoTask = {
json: true,
gzip: true
}).then(rdata => {
console.log(`url: ${url}, result: ${JSON.stringify(rdata)}`);
return rdata;
return this.addLog(url, rdata);
}).catch(e => {
console.error(`execTask err: ${e.message}`);
return {code: 400, message: e.message};
return this.addLog(url, {code: e.statusCode || 500, message: e.message});
});
});
},
addLog(url, rdata) {
let key = `${TASK_KEY_LOG}:${md5(url)}`;
console.log(`url: ${url}, result: ${JSON.stringify(rdata)}`);
rdata = _.isArray(rdata) ? rdata : [rdata];
return redis.ltrimAsync(key, 0, 1000).then(() => {
return Promise.all(_.map(
rdata,
item => redis.lpushAsync(key, JSON.stringify(Object.assign({time: Date.now()}, item)))
));
}).then(() => {
return rdata;
});
}
};
... ...