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
9a8344f8
Commit
9a8344f8
authored
Dec 07, 2019
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
b3b23288
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
193 additions
and
13 deletions
+193
-13
taskexecutor/app/base/db/cache.base.js
+49
-0
taskexecutor/app/base/db/cache/apiAccessControlCache.js
+17
-0
taskexecutor/app/base/db/cache/apiAccessKeyCache.js
+27
-0
taskexecutor/app/base/db/cache/apiAccessKeyCheckCache.js
+34
-0
taskexecutor/app/base/db/cache/magCache.js
+37
-0
taskexecutor/app/base/db/impl/common/connection.js
+2
-0
taskexecutor/app/base/db/task.base.js
+0
-0
taskexecutor/app/base/db/task/test/testTask.js
+1
-0
taskexecutor/app/config/localsettings.js
+1
-2
taskexecutor/app/config/settings.js
+23
-9
taskexecutor/main.js
+2
-2
No files found.
taskexecutor/app/base/db/cache.base.js
0 → 100644
View file @
9a8344f8
const
system
=
require
(
"../system"
)
const
settings
=
require
(
"../../config/settings.js"
);
class
CacheBase
{
constructor
()
{
this
.
redisClient
=
system
.
getObject
(
"util.redisClient"
);
this
.
desc
=
this
.
desc
();
this
.
prefix
=
this
.
prefix
();
this
.
cacheCacheKeyPrefix
=
"sadd_children_appkeys:"
+
settings
.
appKey
+
"_cachekey"
;
this
.
isdebug
=
this
.
isdebug
();
}
isdebug
()
{
return
false
;
}
desc
()
{
throw
new
Error
(
"子类需要定义desc方法,返回缓存描述"
);
}
prefix
()
{
throw
new
Error
(
"子类需要定义prefix方法,返回本缓存的前缀"
);
}
async
cache
(
inputkey
,
val
,
ex
,
...
items
)
{
const
cachekey
=
this
.
prefix
+
inputkey
;
var
cacheValue
=
await
this
.
redisClient
.
get
(
cachekey
);
if
(
!
cacheValue
||
cacheValue
==
"undefined"
||
cacheValue
==
"null"
||
this
.
isdebug
)
{
var
objvalstr
=
await
this
.
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
);
if
(
!
objvalstr
)
{
return
null
;
}
if
(
ex
)
{
await
this
.
redisClient
.
setWithEx
(
cachekey
,
objvalstr
,
ex
);
}
else
{
await
this
.
redisClient
.
set
(
cachekey
,
objvalstr
);
}
//缓存当前应用所有的缓存key及其描述
this
.
redisClient
.
sadd
(
this
.
cacheCacheKeyPrefix
,
[
cachekey
+
"|"
+
this
.
desc
]);
return
JSON
.
parse
(
objvalstr
);
}
else
{
return
JSON
.
parse
(
cacheValue
);
}
}
async
invalidate
(
inputkey
)
{
const
cachekey
=
this
.
prefix
+
inputkey
;
this
.
redisClient
.
delete
(
cachekey
);
return
0
;
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
throw
new
Error
(
"子类中实现构建缓存值的方法,返回字符串"
);
}
}
module
.
exports
=
CacheBase
;
taskexecutor/app/base/db/cache/apiAccessControlCache.js
0 → 100644
View file @
9a8344f8
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
class
ApiAccessControlCache
extends
CacheBase
{
constructor
()
{
super
();
}
desc
()
{
return
"API访问控制缓存"
;
}
prefix
()
{
return
"api_access_control_:"
;
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
return
val
;
}
}
module
.
exports
=
ApiAccessControlCache
;
taskexecutor/app/base/db/cache/apiAccessKeyCache.js
0 → 100644
View file @
9a8344f8
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
const
settings
=
require
(
"../../../config/settings"
);
class
ApiAccessKeyCache
extends
CacheBase
{
constructor
(){
super
();
this
.
restS
=
system
.
getObject
(
"util.restClient"
);
}
desc
(){
return
"应用中缓存访问token"
;
}
prefix
(){
return
"g_accesskey_"
;
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,...
items
){
var
acckapp
=
await
this
.
restS
.
execPost
({
appkey
:
settings
.
appKey
,
secret
:
settings
.
secret
},
settings
.
paasUrl
()
+
"api/auth/accessAuth/getAccessKey"
);
var
s
=
acckapp
.
stdout
;
if
(
s
){
var
tmp
=
JSON
.
parse
(
s
);
if
(
tmp
.
status
==
0
){
return
JSON
.
stringify
(
tmp
.
data
);
}
}
return
null
;
}
}
module
.
exports
=
ApiAccessKeyCache
;
taskexecutor/app/base/db/cache/apiAccessKeyCheckCache.js
0 → 100644
View file @
9a8344f8
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
const
settings
=
require
(
"../../../config/settings"
);
//缓存首次登录的赠送的宝币数量
class
ApiAccessKeyCheckCache
extends
CacheBase
{
constructor
(){
super
();
this
.
restS
=
system
.
getObject
(
"util.restClient"
);
}
desc
(){
return
"应用中来访访问token缓存"
;
}
prefix
(){
return
"g_accesskeycheck_"
;
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,...
items
){
var
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
//当来访key缓存不存在时,需要去开放平台检查是否存在来访key缓存
var
acckapp
=
await
cacheManager
[
"ApiAccessKeyCache"
].
cache
(
settings
.
appKey
,
null
,
ex
);
//先获取本应用accessKey
var
checkresult
=
await
this
.
restS
.
execPostWithAK
({
checkAccessKey
:
inputkey
},
settings
.
paasUrl
()
+
"api/auth/accessAuth/authAccessKey"
,
acckapp
.
accessKey
);
if
(
checkresult
.
status
==
0
){
var
s
=
checkresult
.
data
;
return
JSON
.
stringify
(
s
);
}
else
{
await
cacheManager
[
"ApiAccessKeyCache"
].
invalidate
(
settings
.
appKey
);
var
acckapp
=
await
cacheManager
[
"ApiAccessKeyCache"
].
cache
(
settings
.
appKey
,
null
,
ex
);
//先获取本应用accessKey
var
checkresult
=
await
this
.
restS
.
execPostWithAK
({
checkAccessKey
:
inputkey
},
settings
.
paasUrl
()
+
"api/auth/accessAuth/authAccessKey"
,
acckapp
.
accessKey
);
var
s
=
checkresult
.
data
;
return
JSON
.
stringify
(
s
);
}
}
}
module
.
exports
=
ApiAccessKeyCheckCache
;
taskexecutor/app/base/db/cache/magCache.js
0 → 100644
View file @
9a8344f8
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
class
MagCache
extends
CacheBase
{
constructor
()
{
super
();
this
.
prefix
=
"magCache"
;
}
desc
()
{
return
"缓存管理"
;
}
prefix
()
{
return
"magCache:"
;
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
return
val
;
}
async
getCacheSmembersByKey
(
key
)
{
return
this
.
redisClient
.
smembers
(
key
);
}
async
delCacheBySrem
(
key
,
value
)
{
return
this
.
redisClient
.
srem
(
key
,
value
)
}
async
keys
(
p
)
{
return
this
.
redisClient
.
keys
(
p
);
}
async
get
(
k
)
{
return
this
.
redisClient
.
get
(
k
);
}
async
del
(
k
)
{
return
this
.
redisClient
.
delete
(
k
);
}
async
clearAll
()
{
console
.
log
(
"xxxxxxxxxxxxxxxxxxxclearAll............"
);
return
this
.
redisClient
.
flushall
();
}
}
module
.
exports
=
MagCache
;
taskexecutor/app/base/db/impl/common/connection.js
View file @
9a8344f8
...
...
@@ -6,6 +6,8 @@ var glob = require("glob");
class
DbFactory
{
constructor
(){
const
dbConfig
=
settings
.
database
();
console
.
log
(
"ppppppppppppppppppppppppp"
);
console
.
log
(
dbConfig
);
this
.
db
=
new
Sequelize
(
dbConfig
.
dbname
,
dbConfig
.
user
,
dbConfig
.
password
,
...
...
taskexecutor/app/base/task.base.js
→
taskexecutor/app/base/
db/
task.base.js
View file @
9a8344f8
File moved
taskexecutor/app/base/task/test/testTask.js
→
taskexecutor/app/base/
db/
task/test/testTask.js
View file @
9a8344f8
...
...
@@ -8,6 +8,7 @@ class TestTask extends TaskBase{
//this.isThrough=true;
}
async
subDoTask
(
params
){
console
.
log
(
params
);
console
.
log
(
"TestTask1....."
);
}
}
...
...
taskexecutor/app/config/localsettings.js
View file @
9a8344f8
...
...
@@ -6,9 +6,8 @@ var settings = {
db
:
11
,
},
database
:
function
()
{
var
args
=
process
.
argv
;
return
{
dbname
:
"
alop
"
,
dbname
:
"
tasks
"
,
user
:
"write"
,
password
:
"write"
,
config
:
{
...
...
taskexecutor/app/config/settings.js
View file @
9a8344f8
var
path
=
require
(
'path'
);
var
ENVINPUT
=
{
DB_HOST
:
process
.
env
.
DB_HOST
,
DB_PORT
:
process
.
env
.
DB_PORT
,
DB_USER
:
process
.
env
.
DB_USER
,
DB_PWD
:
process
.
env
.
DB_PWD
,
REDIS_HOST
:
process
.
env
.
REDIS_HOST
,
REDIS_PORT
:
process
.
env
.
REDIS_PORT
,
REDIS_PWD
:
process
.
env
.
REDIS_PWD
,
DB_NAME
:
process
.
env
.
TASK_DB_NAME
,
REDIS_DB
:
process
.
env
.
TASK_REDIS_DB
,
APP_ENV
:
process
.
env
.
APP_ENV
?
process
.
env
.
APP_ENV
:
"dev"
};
var
settings
=
{
env
:
"dev"
,
env
:
ENVINPUT
.
APP_ENV
,
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
port
:
process
.
env
.
NODE_PORT
||
3001
,
redis
:
function
(){
...
...
@@ -9,24 +21,25 @@ var settings = {
return
localsettings
.
redis
;
}
else
{
return
{
host
:
"xxxxx"
,
port
:
xxxxx
,
password
:
"xxxxx"
,
db
:
xx
,
host
:
ENVINPUT
.
REDIS_HOST
,
port
:
ENVINPUT
.
REDIS_PORT
,
password
:
ENVINPUT
.
REDIS_PWD
,
db
:
ENVINPUT
.
REDIS_DB
,
};
}
},
database
:
function
(){
if
(
this
.
env
==
"dev"
){
console
.
log
(
"==========================="
);
var
localsettings
=
require
(
"./localsettings"
);
return
localsettings
.
database
();
}
else
{
return
{
dbname
:
"xxxxx"
,
user
:
"xxxx"
,
password
:
"xxxxx"
,
dbname
:
ENVINPUT
.
DB_NAME
,
user
:
ENVINPUT
.
DB_USER
,
password
:
ENVINPUT
.
DB_PWD
,
config
:
{
host
:
'xxxxxx'
,
host
:
ENVINPUT
.
DB_HOST
,
dialect
:
'mysql'
,
operatorsAliases
:
false
,
pool
:
{
...
...
@@ -45,4 +58,5 @@ var settings = {
}
}
};
settings
.
ENVINPUT
=
ENVINPUT
;
module
.
exports
=
settings
;
taskexecutor/main.js
View file @
9a8344f8
...
...
@@ -6,9 +6,9 @@ con=dbf.getCon();
var
taskName
=
process
.
env
.
TASK_NAME
;
var
params
=
process
.
env
.
TASK_PARAM
;
if
(
taskName
){
var
t
=
system
.
getObject
(
"task.test
."
+
taskName
);
var
t
ask
=
system
.
getObject
(
"task
."
+
taskName
);
(
async
()
=>
{
await
t
.
doTask
(
params
);
await
t
ask
.
doTask
(
params
);
console
.
log
(
"process over............"
);
})();
}
else
{
...
...
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