Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
c4d42762
Commit
c4d42762
authored
Jun 13, 2020
by
宋毅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tj
parent
7b46ecdc
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
77 additions
and
169 deletions
+77
-169
brg-queue-center/app/base/api/api.base.js
+1
-37
brg-queue-center/app/base/api/impl/test/testData.js
+0
-0
brg-queue-center/app/base/db/consumer.base.js
+5
-49
brg-queue-center/app/base/service/app.base.js
+1
-37
brg-queue-center/app/base/service/sve.base.js
+1
-37
brg-queue-center/app/base/utils/execClient.js
+59
-0
brg-queue-center/app/base/utils/redisClient.js
+6
-5
brg-queue-center/app/config/localsettings.js
+1
-1
brg-queue-center/app/config/settings.js
+3
-3
No files found.
brg-queue-center/app/base/api/api.base.js
View file @
c4d42762
...
@@ -42,43 +42,7 @@ class APIBase {
...
@@ -42,43 +42,7 @@ class APIBase {
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
*/
async
execPostByTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
60
)
{
async
execPostByTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
60
)
{
if
(
settings
.
env
===
"dev"
)
{
return
await
this
.
execClient
.
execPostTimeOutByBusiness
(
"api.base"
,
params
,
url
,
ContentType
,
headData
,
timeOut
);
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
;
}
}
/**
/**
* 返回20位业务订单号
* 返回20位业务订单号
...
...
brg-queue-center/app/base/api/impl/test/testData.js
deleted
100755 → 0
View file @
7b46ecdc
This diff is collapsed.
Click to expand it.
brg-queue-center/app/base/db/consumer.base.js
View file @
c4d42762
...
@@ -34,13 +34,9 @@ class ConsumerBase {
...
@@ -34,13 +34,9 @@ class ConsumerBase {
}
}
});
});
}
catch
(
error
)
{
}
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
({
console
.
log
(
error
.
stack
,
",队列执行doConsumer存在异常"
);
optitle
:
this
.
serviceName
+
",队列执行doConsumer存在异常"
,
op
:
"base/db/consumer.base.js"
,
message
:
""
}));
}
}
}
}
...
@@ -76,13 +72,9 @@ class ConsumerBase {
...
@@ -76,13 +72,9 @@ class ConsumerBase {
}
}
execResult
=
await
this
.
subDoConsumer
(
queuedName
,
actionBody
);
execResult
=
await
this
.
subDoConsumer
(
queuedName
,
actionBody
);
}
catch
(
error
)
{
}
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
({
console
.
log
(
error
.
stack
,
",队列执行execSubDoConsumer存在异常"
);
optitle
:
this
.
serviceName
+
",队列执行execSubDoConsumer存在异常"
,
op
:
"base/db/consumer.base.js"
,
message
:
error
.
stack
}));
}
}
}
}
...
@@ -105,43 +97,7 @@ class ConsumerBase {
...
@@ -105,43 +97,7 @@ class ConsumerBase {
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
*/
async
execPostByTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
60
)
{
async
execPostByTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
60
)
{
if
(
settings
.
env
===
"dev"
)
{
return
await
this
.
execClient
.
execPostTimeOutByBusiness
(
"consumer.base"
,
params
,
url
,
ContentType
,
headData
,
timeOut
);
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
;
}
}
/*
/*
返回20位业务订单号
返回20位业务订单号
...
...
brg-queue-center/app/base/service/app.base.js
View file @
c4d42762
...
@@ -16,43 +16,7 @@ class AppServiceBase {
...
@@ -16,43 +16,7 @@ class AppServiceBase {
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
*/
async
execPostByTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
60
)
{
async
execPostByTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
60
)
{
if
(
settings
.
env
===
"dev"
)
{
return
await
this
.
execClient
.
execPostTimeOutByBusiness
(
"app.base"
,
params
,
url
,
ContentType
,
headData
,
timeOut
);
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
;
}
}
async
getConvertSemiangleStr
(
str
)
{
//去除空格及全角转半角
async
getConvertSemiangleStr
(
str
)
{
//去除空格及全角转半角
...
...
brg-queue-center/app/base/service/sve.base.js
View file @
c4d42762
...
@@ -23,43 +23,7 @@ class ServiceBase {
...
@@ -23,43 +23,7 @@ class ServiceBase {
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
*/
async
execPostByTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
60
)
{
async
execPostByTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
60
)
{
if
(
settings
.
env
===
"dev"
)
{
return
await
this
.
execClient
.
execPostTimeOutByBusiness
(
"sve.base"
,
params
,
url
,
ContentType
,
headData
,
timeOut
);
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
;
}
}
async
create
(
qobj
)
{
async
create
(
qobj
)
{
return
this
.
dao
.
create
(
qobj
);
return
this
.
dao
.
create
(
qobj
);
...
...
brg-queue-center/app/base/utils/execClient.js
View file @
c4d42762
var
childproc
=
require
(
'child_process'
);
var
childproc
=
require
(
'child_process'
);
const
system
=
require
(
"../system"
);
const
util
=
require
(
'util'
);
const
util
=
require
(
'util'
);
const
exec
=
util
.
promisify
(
require
(
'child_process'
).
exec
);
const
exec
=
util
.
promisify
(
require
(
'child_process'
).
exec
);
const
settings
=
require
(
"../../../app/config/settings"
);
const
axios
=
require
(
'axios'
);
class
ExecClient
{
class
ExecClient
{
constructor
()
{
constructor
()
{
this
.
cmdGetPattern
=
"curl -G -X GET '{url}'"
;
this
.
cmdGetPattern
=
"curl -G -X GET '{url}'"
;
this
.
cmdPostPattern
=
"curl -k -H 'Content-type: application/json' -d '{data}' {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.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请求
* get请求
* @param {*} params 提交的数据-格式JSON
* @param {*} params 提交的数据-格式JSON
* @param {*} url
* @param {*} url
...
...
brg-queue-center/app/base/utils/redisClient.js
View file @
c4d42762
...
@@ -5,6 +5,7 @@ const bluebird = require("bluebird");
...
@@ -5,6 +5,7 @@ const bluebird = require("bluebird");
bluebird
.
promisifyAll
(
redis
);
bluebird
.
promisifyAll
(
redis
);
class
RedisClient
{
class
RedisClient
{
constructor
()
{
constructor
()
{
this
.
redisConfig
=
settings
.
redis
();
this
.
client
=
this
.
getCreateClientInstance
();
this
.
client
=
this
.
getCreateClientInstance
();
this
.
subclient
=
this
.
client
.
duplicate
();
this
.
subclient
=
this
.
client
.
duplicate
();
...
@@ -56,12 +57,12 @@ class RedisClient {
...
@@ -56,12 +57,12 @@ class RedisClient {
return
this
.
subclient
;
return
this
.
subclient
;
}
}
getCreateClientInstance
()
{
getCreateClientInstance
()
{
const
redisConfig
=
settings
.
redis
()
const
self
=
this
;
return
redis
.
createClient
({
return
redis
.
createClient
({
host
:
redisConfig
.
host
,
host
:
self
.
redisConfig
.
host
,
port
:
redisConfig
.
port
,
port
:
self
.
redisConfig
.
port
,
password
:
redisConfig
.
password
,
password
:
self
.
redisConfig
.
password
,
db
:
redisConfig
.
db
,
db
:
self
.
redisConfig
.
db
,
retry_strategy
:
function
(
options
)
{
retry_strategy
:
function
(
options
)
{
if
(
options
.
total_retry_time
>
1000
*
60
*
60
)
{
if
(
options
.
total_retry_time
>
1000
*
60
*
60
)
{
return
new
Error
(
'Retry time exhausted'
);
return
new
Error
(
'Retry time exhausted'
);
...
...
brg-queue-center/app/config/localsettings.js
View file @
c4d42762
...
@@ -5,7 +5,7 @@ var settings = {
...
@@ -5,7 +5,7 @@ var settings = {
host
:
"43.247.184.32"
,
host
:
"43.247.184.32"
,
port
:
8967
,
port
:
8967
,
password
:
"Gongsibao2018"
,
password
:
"Gongsibao2018"
,
db
:
5
,
db
:
4
,
},
},
database
:
{
database
:
{
dbname
:
"tx-queue-log"
,
dbname
:
"tx-queue-log"
,
...
...
brg-queue-center/app/config/settings.js
View file @
c4d42762
...
@@ -10,15 +10,15 @@ var ENVINPUT = {
...
@@ -10,15 +10,15 @@ var ENVINPUT = {
REDIS_DB
:
process
.
env
.
TASK_REDIS_DB
,
REDIS_DB
:
process
.
env
.
TASK_REDIS_DB
,
DB_NAME
:
process
.
env
.
TASK_DB_NAME
,
DB_NAME
:
process
.
env
.
TASK_DB_NAME
,
APP_ENV
:
process
.
env
.
APP_ENV
?
process
.
env
.
APP_ENV
:
"test"
,
//运行环境
APP_ENV
:
process
.
env
.
APP_ENV
?
process
.
env
.
APP_ENV
:
"test"
,
//运行环境
CONSUMER_NAME
:
process
.
env
.
CONSUMER_NAME
||
"public
Logs.publicLogs
Consumer"
,
//消费者名称
CONSUMER_NAME
:
process
.
env
.
CONSUMER_NAME
||
"public
ServiceAllocation.public
Consumer"
,
//消费者名称
QUEUED_NAME
:
process
.
env
.
QUEUED_NAME
||
"
LOGS-
SYTXPUBLIC-MSGQ"
,
//队列名称,FAIL-失败队列(队列和失败队列一对存在进行部署)
QUEUED_NAME
:
process
.
env
.
QUEUED_NAME
||
"SYTXPUBLIC-MSGQ"
,
//队列名称,FAIL-失败队列(队列和失败队列一对存在进行部署)
};
};
var
settings
=
{
var
settings
=
{
env
:
ENVINPUT
.
APP_ENV
,
env
:
ENVINPUT
.
APP_ENV
,
consumerName
:
ENVINPUT
.
CONSUMER_NAME
,
consumerName
:
ENVINPUT
.
CONSUMER_NAME
,
queuedName
:
ENVINPUT
.
QUEUED_NAME
,
queuedName
:
ENVINPUT
.
QUEUED_NAME
,
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
port
:
process
.
env
.
NODE_PORT
||
8081
,
port
:
process
.
env
.
NODE_PORT
||
4018
,
redis
:
function
()
{
redis
:
function
()
{
if
(
this
.
env
==
"dev"
||
this
.
env
==
"test"
)
{
if
(
this
.
env
==
"dev"
||
this
.
env
==
"test"
)
{
var
localsettings
=
require
(
"./localsettings"
);
var
localsettings
=
require
(
"./localsettings"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment