Commit c4d42762 by 宋毅

tj

parent 7b46ecdc
......@@ -42,43 +42,7 @@ class APIBase {
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
async execPostByTimeOut(params, url, ContentType, headData, timeOut = 60) {
if (settings.env === "dev") {
var headers = {
'Content-type': 'application/json'
}
if (headData) {
var headDataKeys = Object.keys(headData);
if (headDataKeys.length > 0) {
for (let index = 0; index < headDataKeys.length; index++) {
const indexKey = headDataKeys[index];
var headValue = headData[indexKey];
if (indexKey && headValue) {
headers[indexKey] = headValue;
}
}
}
}
axios.default.timeout = timeOut;
let result = await axios({
// headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: headers,
method: 'POST',
url: url,
data: JSON.stringify(params)
});
if (result.status == 200 && result.data) {
return result.data;
}
this.errorLogDao.addOpErrorLogs(queuedName + "执行execPostEs存在错误", params, result, null, 3);
return system.getResult(null, "执行execPostEs存在错误");
}
//方式二
var rtn = await this.execClient.execPostTimeOut(params, url, ContentType, headData, timeOut);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPostTimeOut data is empty");
}
var result = JSON.parse(rtn.stdout);
return result;
return await this.execClient.execPostTimeOutByBusiness("api.base", params, url, ContentType, headData, timeOut);
}
/**
* 返回20位业务订单号
......
......@@ -34,13 +34,9 @@ class ConsumerBase {
}
});
} catch (error) {
this.errorLogDao.addOpErrorLogs(queuedName + "队列执行doConsumer存在异常", null, null, error.stack, 3);
this.errorLogDao.addOpErrorLogs("队列执行doConsumer存在异常", null, null, error.stack, 3);
//日志
console.log(JSON.stringify({
optitle: this.serviceName + ",队列执行doConsumer存在异常",
op: "base/db/consumer.base.js",
message: ""
}));
console.log(error.stack, ",队列执行doConsumer存在异常");
}
}
......@@ -76,13 +72,9 @@ class ConsumerBase {
}
execResult = await this.subDoConsumer(queuedName, actionBody);
} catch (error) {
this.errorLogDao.addOpErrorLogs(queuedName + "队列执行execSubDoConsumer存在异常", actionBody, execResult, error.stack, 3);
this.errorLogDao.addOpErrorLogs("队列执行execSubDoConsumer存在异常", actionBody, execResult, error.stack, 3);
//日志记录
console.log(JSON.stringify({
optitle: this.serviceName + ",队列执行execSubDoConsumer存在异常",
op: "base/db/consumer.base.js",
message: error.stack
}));
console.log(error.stack, ",队列执行execSubDoConsumer存在异常");
}
}
......@@ -105,43 +97,7 @@ class ConsumerBase {
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
async execPostByTimeOut(params, url, ContentType, headData, timeOut = 60) {
if (settings.env === "dev") {
var headers = {
'Content-type': 'application/json'
}
if (headData) {
var headDataKeys = Object.keys(headData);
if (headDataKeys.length > 0) {
for (let index = 0; index < headDataKeys.length; index++) {
const indexKey = headDataKeys[index];
var headValue = headData[indexKey];
if (indexKey && headValue) {
headers[indexKey] = headValue;
}
}
}
}
axios.default.timeout = timeOut;
let result = await axios({
// headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: headers,
method: 'POST',
url: url,
data: JSON.stringify(params)
});
if (result.status == 200 && result.data) {
return result.data;
}
this.errorLogDao.addOpErrorLogs(queuedName + "执行execPostEs存在错误", params, result, null, 3);
return system.getResult(null, "执行execPostEs存在错误");
}
//方式二
var rtn = await this.execClient.execPostTimeOut(params, url, ContentType, headData, timeOut);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPostTimeOut data is empty");
}
var result = JSON.parse(rtn.stdout);
return result;
return await this.execClient.execPostTimeOutByBusiness("consumer.base", params, url, ContentType, headData, timeOut);
}
/*
返回20位业务订单号
......
......@@ -16,43 +16,7 @@ class AppServiceBase {
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
async execPostByTimeOut(params, url, ContentType, headData, timeOut = 60) {
if (settings.env === "dev") {
var headers = {
'Content-type': 'application/json'
}
if (headData) {
var headDataKeys = Object.keys(headData);
if (headDataKeys.length > 0) {
for (let index = 0; index < headDataKeys.length; index++) {
const indexKey = headDataKeys[index];
var headValue = headData[indexKey];
if (indexKey && headValue) {
headers[indexKey] = headValue;
}
}
}
}
axios.default.timeout = timeOut;
let result = await axios({
// headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: headers,
method: 'POST',
url: url,
data: JSON.stringify(params)
});
if (result.status == 200 && result.data) {
return result.data;
}
this.errorLogDao.addOpErrorLogs(queuedName + "执行execPostEs存在错误", params, result, null, 3);
return system.getResult(null, "执行execPostEs存在错误");
}
//方式二
var rtn = await this.execClient.execPostTimeOut(params, url, ContentType, headData, timeOut);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPostTimeOut data is empty");
}
var result = JSON.parse(rtn.stdout);
return result;
return await this.execClient.execPostTimeOutByBusiness("app.base", params, url, ContentType, headData, timeOut);
}
async getConvertSemiangleStr(str) {//去除空格及全角转半角
......
......@@ -23,43 +23,7 @@ class ServiceBase {
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
async execPostByTimeOut(params, url, ContentType, headData, timeOut = 60) {
if (settings.env === "dev") {
var headers = {
'Content-type': 'application/json'
}
if (headData) {
var headDataKeys = Object.keys(headData);
if (headDataKeys.length > 0) {
for (let index = 0; index < headDataKeys.length; index++) {
const indexKey = headDataKeys[index];
var headValue = headData[indexKey];
if (indexKey && headValue) {
headers[indexKey] = headValue;
}
}
}
}
axios.default.timeout = timeOut;
let result = await axios({
// headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: headers,
method: 'POST',
url: url,
data: JSON.stringify(params)
});
if (result.status == 200 && result.data) {
return result.data;
}
this.errorLogDao.addOpErrorLogs(queuedName + "执行execPostEs存在错误", params, result, null, 3);
return system.getResult(null, "执行execPostEs存在错误");
}
//方式二
var rtn = await this.execClient.execPostTimeOut(params, url, ContentType, headData, timeOut);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPostTimeOut data is empty");
}
var result = JSON.parse(rtn.stdout);
return result;
return await this.execClient.execPostTimeOutByBusiness("sve.base", params, url, ContentType, headData, timeOut);
}
async create(qobj) {
return this.dao.create(qobj);
......
var childproc = require('child_process');
const system = require("../system");
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const settings = require("../../../app/config/settings");
const axios = require('axios');
class ExecClient {
constructor() {
this.cmdGetPattern = "curl -G -X GET '{url}'";
this.cmdPostPattern = "curl -k -H 'Content-type: application/json' -d '{data}' {url}";
// this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'request-id:{requestId}' -d '{data}' {url}"; //--已废弃
this.errorLogDao = system.getObject("db.opLogs.errorLogDao");
}
/**
* 带超时时间的post请求
* @param {*} execFile 执行文件
* @param {*} params 请求数据-json格式
* @param {*} url 请求地址
* @param {*} ContentType 请求头类型,默认application/json
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} timeOut 超时时间设置,单位秒
*/
async execPostTimeOutByBusiness(execFile, params, url, ContentType, headData, timeOut = 5000) {
var rtn = null;
try {
if (settings.env === "dev") {
var headers = {
'Content-type': 'application/json'
}
if (headData) {
var headDataKeys = Object.keys(headData);
if (headDataKeys.length > 0) {
for (let index = 0; index < headDataKeys.length; index++) {
const indexKey = headDataKeys[index];
var headValue = headData[indexKey];
if (indexKey && headValue) {
headers[indexKey] = headValue;
}
}
}
}
axios.default.timeout = timeOut;
let result = await axios({
// headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: headers,
method: 'POST',
url: url,
data: JSON.stringify(params)
});
if (result.status == 200 && result.data) {
return result.data;
}
this.errorLogDao.addOpErrorLogs(queuedName + "执行execPostTimeOutByBusiness存在错误", params, result, null, 3);
return system.getResult(null, "执行execPostTimeOutByBusiness存在错误");
}
//方式二
rtn = await this.execPostTimeOut(params, url, ContentType, headData, timeOut);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPostTimeOut data is empty");
}
var result = JSON.parse(rtn.stdout);
return result;
} catch (error) {
this.errorLogDao.addOpErrorLogs(execFile + "执行execPostByTimeOut存在异常", params, rtn.stdout, error.stack, 3);
return system.getResultFail(-200, execFile + "执行execPostByTimeOut存在异常");
}
}
/**
* get请求
* @param {*} params 提交的数据-格式JSON
* @param {*} url
......
......@@ -5,6 +5,7 @@ const bluebird = require("bluebird");
bluebird.promisifyAll(redis);
class RedisClient {
constructor() {
this.redisConfig = settings.redis();
this.client = this.getCreateClientInstance();
this.subclient = this.client.duplicate();
......@@ -56,12 +57,12 @@ class RedisClient {
return this.subclient;
}
getCreateClientInstance() {
const redisConfig = settings.redis()
const self = this;
return redis.createClient({
host: redisConfig.host,
port: redisConfig.port,
password: redisConfig.password,
db: redisConfig.db,
host: self.redisConfig.host,
port: self.redisConfig.port,
password: self.redisConfig.password,
db: self.redisConfig.db,
retry_strategy: function (options) {
if (options.total_retry_time > 1000 * 60 * 60) {
return new Error('Retry time exhausted');
......
......@@ -5,7 +5,7 @@ var settings = {
host: "43.247.184.32",
port: 8967,
password: "Gongsibao2018",
db: 5,
db: 4,
},
database: {
dbname: "tx-queue-log",
......
......@@ -10,15 +10,15 @@ var ENVINPUT = {
REDIS_DB: process.env.TASK_REDIS_DB,
DB_NAME: process.env.TASK_DB_NAME,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "test",//运行环境
CONSUMER_NAME: process.env.CONSUMER_NAME || "publicLogs.publicLogsConsumer",//消费者名称
QUEUED_NAME: process.env.QUEUED_NAME || "LOGS-SYTXPUBLIC-MSGQ",//队列名称,FAIL-失败队列(队列和失败队列一对存在进行部署)
CONSUMER_NAME: process.env.CONSUMER_NAME || "publicServiceAllocation.publicConsumer",//消费者名称
QUEUED_NAME: process.env.QUEUED_NAME || "SYTXPUBLIC-MSGQ",//队列名称,FAIL-失败队列(队列和失败队列一对存在进行部署)
};
var settings = {
env: ENVINPUT.APP_ENV,
consumerName: ENVINPUT.CONSUMER_NAME,
queuedName: ENVINPUT.QUEUED_NAME,
basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 8081,
port: process.env.NODE_PORT || 4018,
redis: function () {
if (this.env == "dev" || this.env == "test") {
var localsettings = require("./localsettings");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment