Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sb_h5
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data_server
sb_h5
Commits
8210eef2
Commit
8210eef2
authored
Mar 01, 2019
by
高诸锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
f381bd1b
Pipeline
#3990
passed with stage
in 2 seconds
Changes
10
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
85 additions
and
39 deletions
+85
-39
task.js
app/controller/task.js
+2
-1
application.js
app/extend/application.js
+40
-13
cache.js
app/service/cache.js
+5
-5
partner.js
app/service/partner.js
+2
-2
scripts.js
app/service/scripts.js
+4
-4
storage.js
app/service/storage.js
+1
-1
washData.js
app/service/washData.js
+2
-2
config.local.js
config/config.local.js
+12
-3
config.prod.js
config/config.prod.js
+16
-7
plugin.js
config/plugin.js
+1
-1
No files found.
app/controller/task.js
View file @
8210eef2
...
...
@@ -120,13 +120,14 @@ class TaskController extends Controller {
const
{
orderId
,
appkey
}
=
order
;
insertData
.
orderId
=
orderId
;
insertData
.
cityName
=
insertData
.
location
;
// TODO insertData.cityId -> cityName
insertData
.
taskId
=
taskId
;
insertData
.
appKey
=
appkey
;
delete
insertData
.
code
;
await
service
.
storage
.
write
(
insertData
);
await
service
.
partner
.
notify
({
taskId
,
cb
:
order
.
callbackUrl
,
orderId
:
order
.
orderId
,
userId
:
order
.
userId
});
}
catch
(
err
)
{
ctx
.
logger
.
err
or
(
'handleCallback'
,
err
,
result
);
ctx
.
logger
.
err
(
`【controller/task/handleCallback err】:
${
err
}${
JSON
.
stringify
(
result
)}
`
);
taskNote
=
{
status
:
'failure'
,
note
:
{
message
:
err
.
message
},
...
...
app/extend/application.js
View file @
8210eef2
'use strict'
;
const
REDIS_CACHE
=
Symbol
(
'Context#RedisCache'
);
const
NODE_CACHE
=
Symbol
(
'Context#NodeCache'
);
const
NodeCache
=
require
(
'node-cache'
);
const
INCR_SCRIPT
=
'return redis.call("INCR", ARGV[1])'
;
class
Cache
{
constructor
(
app
)
{
this
.
app
=
app
;
this
.
name
=
'unknown-cache'
;
this
.
app
.
redis
.
defineCommand
(
'INCR'
,
{
numberOfKeys
:
0
,
lua
:
INCR_SCRIPT
,
});
}
async
val
(
key
,
next
,
ttl
)
{
...
...
@@ -36,19 +42,39 @@ class Cache {
jsonText
=
jsonText
.
substr
(
0
,
125
)
+
'...'
;
}
}
this
.
app
.
logger
.
info
(
`
【Cache Get:】
(
${
+
new
Date
()
-
startTime
}
ms)
${
this
.
name
}
.
${
key
}
:
${
jsonText
}
`
);
this
.
app
.
logger
.
info
(
`
[cache]
(
${
+
new
Date
()
-
startTime
}
ms)
${
this
.
name
}
.
${
key
}
:
${
jsonText
}
`
);
return
ret
;
}
async
set
(
key
,
value
,
ttl
=
60
)
{
const
startTime
=
+
new
Date
();
await
this
.
_set
(
key
,
value
,
ttl
);
this
.
app
.
logger
.
info
(
`【Cache Set】(
${
+
new
Date
()
-
startTime
}
ms) Key:
${
key
}
value:
${
JSON
.
stringify
(
value
)}
`
);
return
;
return
await
this
.
_set
(
key
,
value
,
ttl
);
}
}
async
del
(
key
)
{
if
(
key
)
{
return
await
this
.
_del
(
key
);
class
RedisCacheWrap
extends
Cache
{
constructor
(
app
,
redis
)
{
super
(
app
);
this
.
redis
=
redis
;
this
.
name
=
'redis-cache'
;
}
async
_get
(
key
)
{
const
{
redis
}
=
this
;
let
value
=
await
redis
.
get
(
key
);
if
(
value
===
null
)
{
value
=
undefined
;
}
if
(
value
)
{
value
=
JSON
.
parse
(
value
);
}
return
value
;
}
async
_set
(
key
,
value
,
ttl
)
{
const
{
redis
}
=
this
;
value
=
JSON
.
stringify
(
value
);
if
(
ttl
>
0
)
{
await
redis
.
set
(
key
,
value
,
'EX'
,
ttl
);
}
else
{
await
redis
.
set
(
key
,
value
);
}
}
}
...
...
@@ -63,7 +89,6 @@ class NodeCacheWrap extends Cache {
async
_get
(
key
)
{
return
this
.
cache
.
get
(
key
);
}
async
_set
(
key
,
value
,
ttl
)
{
const
{
cache
}
=
this
;
value
=
JSON
.
parse
(
JSON
.
stringify
(
value
));
...
...
@@ -73,13 +98,15 @@ class NodeCacheWrap extends Cache {
cache
.
set
(
key
,
value
);
}
}
async
_del
(
key
)
{
return
this
.
cache
.
del
(
key
);
}
}
module
.
exports
=
{
get
memcache
()
{
if
(
!
this
[
REDIS_CACHE
])
{
this
[
REDIS_CACHE
]
=
new
RedisCacheWrap
(
this
,
this
.
redis
);
}
return
this
[
REDIS_CACHE
];
},
get
cache
()
{
if
(
!
this
[
NODE_CACHE
])
{
this
[
NODE_CACHE
]
=
new
NodeCacheWrap
(
this
);
...
...
app/service/cache.js
View file @
8210eef2
...
...
@@ -12,7 +12,7 @@ class CacheService extends Service {
}
/**
* 将taskId状态缓存到
cache
和数据库
* 将taskId状态缓存到
redis
和数据库
* @param {Object} key taskId
* - value: 状态 提示信息 status 、note={}
* - exprie: 过期时间(单位/s)
...
...
@@ -20,9 +20,9 @@ class CacheService extends Service {
async
set
({
key
,
value
=
{},
expire
=
300
})
{
const
{
ctx
,
app
,
taskPrefix
}
=
this
;
const
data
=
await
app
.
cache
.
get
(
taskPrefix
+
key
);
const
data
=
await
app
.
mem
cache
.
get
(
taskPrefix
+
key
);
if
(
!
data
||
(
data
&&
data
.
status
!==
'success'
))
{
await
app
.
cache
.
set
(
taskPrefix
+
key
,
value
,
expire
);
await
app
.
mem
cache
.
set
(
taskPrefix
+
key
,
value
,
expire
);
}
const
order
=
await
ctx
.
model
.
TaskStatus
.
findOne
({
...
...
@@ -42,9 +42,9 @@ class CacheService extends Service {
*/
async
get
({
key
})
{
const
{
ctx
,
app
,
taskPrefix
}
=
this
;
const
data
=
await
app
.
cache
.
get
(
taskPrefix
+
key
);
const
data
=
await
app
.
mem
cache
.
get
(
taskPrefix
+
key
);
if
(
data
)
{
ctx
.
logger
.
info
(
`【Cache】get From
node-cache
${
key
}
data:`
,
data
);
ctx
.
logger
.
info
(
`【Cache】get From
redis
${
key
}
data:`
,
data
);
return
data
;
}
const
order
=
await
ctx
.
model
.
TaskStatus
.
findOne
({
...
...
app/service/partner.js
View file @
8210eef2
...
...
@@ -17,7 +17,7 @@ class PartnerService extends Service {
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
redisThemePrefix
+
appKey
,
'result:'
,
data
,
err
);
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
redisThemePrefix
+
appKey
,
'result:'
,
JSON
.
stringify
(
data
)
,
err
);
await
this
.
app
.
cache
.
del
(
redisThemePrefix
+
appKey
);
}
}
...
...
@@ -44,7 +44,7 @@ class PartnerService extends Service {
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Partner】 fetchScripts'
,
redisScriptsPrefix
+
appKey
,
'result:'
,
data
,
err
);
ctx
.
logger
.
error
(
'【Partner】 fetchScripts'
,
redisScriptsPrefix
+
appKey
,
'result:'
,
JSON
.
stringify
(
data
)
,
err
);
await
this
.
app
.
cache
.
del
(
redisScriptsPrefix
+
appKey
);
}
}
...
...
app/service/scripts.js
View file @
8210eef2
...
...
@@ -24,7 +24,7 @@ class ScriptsService extends Service {
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchScriptsFromRedis'
,
'result:'
,
data
,
err
);
ctx
.
logger
.
error
(
'【Scripts】fetchScriptsFromRedis'
,
'result:'
,
JSON
.
stringify
(
data
)
,
err
);
await
this
.
app
.
redis
.
del
(
redisScriptsKey
);
}
}
...
...
@@ -34,7 +34,7 @@ class ScriptsService extends Service {
dataType
:
'json'
,
contentType
:
'json'
,
});
ctx
.
logger
.
info
(
`【Scripts】fetchScripts,
${
baseURL
+
fetchScriptsUrl
}
`
,
'result:'
,
result
.
data
);
ctx
.
logger
.
info
(
`【Scripts】fetchScripts,
${
baseURL
+
fetchScriptsUrl
}
`
,
'result:'
,
JSON
.
stringify
(
result
.
data
)
);
if
(
result
.
data
&&
result
.
data
.
length
>
0
)
{
await
this
.
app
.
redis
.
set
(
redisScriptsKey
,
JSON
.
stringify
(
result
.
data
),
'EX'
,
300
);
}
...
...
@@ -60,7 +60,7 @@ class ScriptsService extends Service {
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
'result:'
,
data
,
err
);
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
'result:'
,
JSON
.
stringify
(
data
)
,
err
);
await
this
.
app
.
redis
.
del
(
redisParamsKey
);
}
}
...
...
@@ -136,7 +136,7 @@ class ScriptsService extends Service {
if
(
result
.
data
.
status
===
0
)
{
return
result
.
data
.
content
.
address_detail
.
city
;
}
ctx
.
logger
.
error
(
'fetchCityFormIp'
,
url
,
result
.
data
);
ctx
.
logger
.
error
(
'fetchCityFormIp'
,
url
,
JSON
.
stringify
(
result
.
data
)
);
return
'北京市'
;
}
...
...
app/service/storage.js
View file @
8210eef2
...
...
@@ -51,7 +51,7 @@ class StorageService extends Service {
ctx
.
logger
.
info
(
`【Storage】read url:
${
readUrl
}
/
${
orderId
}
`
);
if
(
result
&&
result
.
data
&&
result
.
data
.
code
!==
0
)
{
ctx
.
logger
.
error
(
`storageAPI read
${
readUrl
}
/
${
orderId
}
`
,
result
.
data
);
ctx
.
logger
.
error
(
`storageAPI read
${
readUrl
}
/
${
orderId
}
`
,
JSON
.
stringify
(
result
.
data
)
);
ctx
.
throw
(
400
,
{
message
:
result
.
data
.
msg
});
}
return
result
.
data
.
data
[
readDataKey
];
...
...
app/service/washData.js
View file @
8210eef2
...
...
@@ -21,11 +21,11 @@ class WashDataService extends Service {
contentType
:
'json'
,
});
if
(
washData
.
status
!==
200
)
{
ctx
.
logger
.
error
(
`【washData】url
${
washUrl
}
,params`
,
rawdata
,
washData
);
ctx
.
logger
.
error
(
`【washData】url
${
washUrl
}
,params`
,
JSON
.
stringify
(
rawdata
),
JSON
.
stringify
(
washData
)
);
throw
new
Error
(
'清洗数据出错'
);
}
if
(
washData
.
data
.
code
!==
0
)
{
ctx
.
logger
.
error
(
`【washData】url
${
washUrl
}
,params`
,
rawdata
,
washData
.
data
);
ctx
.
logger
.
error
(
`【washData】url
${
washUrl
}
,params`
,
JSON
.
stringify
(
rawdata
),
JSON
.
stringify
(
washData
.
data
)
);
throw
new
Error
(
'清洗数据出错'
);
}
...
...
config/config.local.js
View file @
8210eef2
...
...
@@ -17,10 +17,10 @@ module.exports = () => {
host
:
'https://dev-nginx.jianbing.com/zeus-api/v1'
,
fetchTheme
:
'/chaos/partners/theme'
,
fetchScripts
:
'/chaos/partners/scripts'
,
redisThemePrefix
:
'
PARNTERS
.THEME'
,
redisScriptsPrefix
:
'
PARNTERS
.SCRIPTS'
,
redisThemePrefix
:
'
DATA_SERVER_SHEBAO
.THEME'
,
redisScriptsPrefix
:
'
DATA_SERVER_SHEBAO
.SCRIPTS'
,
fetchAgreements
:
''
,
redisAgreementsPrefix
:
'
PARNTERS.Agreements
'
,
redisAgreementsPrefix
:
'
DATA_SERVER_SHEBAO.AGREEMENTS
'
,
};
config
.
scriptsAPI
=
{
...
...
@@ -67,6 +67,15 @@ module.exports = () => {
taskPrefix
:
'NEWSB.TASK'
,
};
config
.
redis
=
{
client
:
{
port
:
6379
,
host
:
'116.62.55.137'
,
password
:
'DEV8redis'
,
db
:
0
,
},
};
config
.
sequelize
=
{
datasources
:
[{
// 东八时区
...
...
config/config.prod.js
View file @
8210eef2
...
...
@@ -5,7 +5,7 @@ module.exports = () => {
config
.
debug
=
false
;
config
.
taskAPI
=
{
host
:
'http://tm.51gjj.com:4831'
,
host
:
process
.
env
.
TASKAPI_HOST
||
'http://tm.51gjj.com:4831'
,
fetchHubsUrl
:
''
,
createTaskUrl
:
'/shebao/createSbTask'
,
fetchCodeUrl
:
'/shebao/getSbCode'
,
...
...
@@ -14,7 +14,7 @@ module.exports = () => {
};
config
.
partnerAPI
=
{
host
:
'https://dev-nginx.jianbing.com/zeus-api/v1'
,
host
:
process
.
env
.
PARTNERAPI_HOST
||
'https://dev-nginx.jianbing.com/zeus-api/v1'
,
fetchTheme
:
'/chaos/partners/theme'
,
fetchScripts
:
'/chaos/partners/scripts'
,
redisThemePrefix
:
'URANUS.HF.PARNTERS.THEME'
,
...
...
@@ -22,7 +22,7 @@ module.exports = () => {
};
config
.
scriptsAPI
=
{
host
:
'https://dev-nginx.jianbing.com/zeus-api/v1'
,
host
:
process
.
env
.
SCRIPTSAPI_HOST
||
'https://dev-nginx.jianbing.com/zeus-api/v1'
,
fetchScriptsUrl
:
'/chaos/hf/two_dimension_array/queries'
,
fetchOneScriptUrl
:
'/chaos/hf/two_dimension_array/info'
,
fetchParamsInfoUrl
:
'/chaos/hf/login_param_map'
,
...
...
@@ -36,7 +36,7 @@ module.exports = () => {
};
config
.
storageAPI
=
{
host
:
'http://tv.51gjj.com:11252'
,
host
:
process
.
env
.
STORAGEAPI_HOST
||
'http://tv.51gjj.com:11252'
,
writeUrl
:
'/data'
,
readUrl
:
'/shebao'
,
writeType
:
'shebao'
,
...
...
@@ -44,12 +44,12 @@ module.exports = () => {
};
config
.
washAPI
=
{
host
:
'http://tt.51gjj.com:11101'
,
host
:
process
.
env
.
WASHAPI_HOST
||
'http://tt.51gjj.com:11101'
,
washUrl
:
'/si/analyzeSI'
,
};
config
.
signatureAPI
=
{
host
:
'http://tj3.51gjj.com:5118'
,
host
:
process
.
env
.
SIGNATUREAPI_HOST
||
'http://tj3.51gjj.com:5118'
,
fetchTokenUrl
:
'/Access/GetToken'
,
fetchOrderIdUrl
:
'/Order/GetOrderSn'
,
signatureUrl
:
'/Access/SignValidityCheck'
,
...
...
@@ -91,12 +91,21 @@ module.exports = () => {
}],
};
config
.
redis
=
{
client
:
{
port
:
6379
,
host
:
process
.
env
.
REDIS_HOST
||
'116.62.55.137'
,
password
:
process
.
env
.
REDIS_PWD
||
'DEV8redis'
,
db
:
0
,
},
};
config
.
SB_OpenAPI
=
{
appKey
:
'60670203E411FD62BA9E953CFB73F881'
,
appSecret
:
'0BDD1ECC147503C477563E5C1438C366D70E4F80'
,
};
config
.
callbackUrl
=
'http://ti.51gjj.com:7001/shebao_server/callback'
;
config
.
callbackUrl
=
process
.
env
.
CALLBACK_URL
||
'http://ti.51gjj.com:7001/shebao_server/callback'
;
return
config
;
};
config/plugin.js
View file @
8210eef2
...
...
@@ -14,7 +14,7 @@ exports.sequelize = {
};
exports
.
redis
=
{
enable
:
fals
e
,
enable
:
tru
e
,
package
:
'egg-redis'
,
};
...
...
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