Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
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
方斌
51business
Commits
3dcd4167
Commit
3dcd4167
authored
Aug 15, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
2ac07526
Pipeline
#12315
passed with stage
in 5 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
7 deletions
+46
-7
HuaYunPaas.js
app/schedule/HuaYunPaas.js
+46
-7
No files found.
app/schedule/HuaYunPaas.js
View file @
3dcd4167
...
...
@@ -8,8 +8,8 @@ class HuaYunPaas extends Subscription {
// 通过 schedule 属性来设置定时任务的执行间隔等配置
static
get
schedule
()
{
return
{
// cron: '0 50 5 * * *',//每天8
:50点执行
cron
:
'*/1 * * * *'
,
//每1分钟执行一次脚本
cron
:
'0 50 4 * * *'
,
//每天4
:50点执行
//
cron: '*/1 * * * *',//每1分钟执行一次脚本
type
:
'worker'
,
env
:
[
'prod'
],
immediate
:
false
...
...
@@ -18,28 +18,36 @@ class HuaYunPaas extends Subscription {
// subscribe 是真正定时任务执行时被运行的函数
async
subscribe
()
{
const
{
ctx
,
app
}
=
this
;
if
([
'https://
dev
-nginx.jianbing.com'
].
includes
(
this
.
config
.
NODE_BASE_URL
))
{
if
([
'https://
uat
-nginx.jianbing.com'
].
includes
(
this
.
config
.
NODE_BASE_URL
))
{
//用redis的setnx来实现锁机制
let
lock
=
'huayun:pass:cron:'
+
moment
().
format
(
'MMDD'
);
ctx
.
logger
.
info
(
lock
);
ctx
.
logger
.
info
(
JSON
.
stringify
(
await
app
.
redis
.
get
(
lock
)));
let
redRes
=
await
app
.
redis
.
setnx
(
lock
,
1
);
ctx
.
logger
.
info
(
'in cron'
);
await
app
.
redis
.
expire
(
lock
,
2
);
if
(
Number
(
redRes
)
===
1
)
{
await
app
.
redis
.
expire
(
lock
,
2
);
ctx
.
logger
.
info
(
'in redis'
);
await
this
.
logic
();
}
}
}
async
logic
()
{
async
logic
(){
const
{
ctx
}
=
this
;
ctx
.
logger
.
info
(
'in logic'
);
const
accessToken
=
await
this
.
getAccessToken
();
await
this
.
callIn
(
accessToken
);
await
this
.
callOut
(
accessToken
);
}
async
callIn
(
accessToken
)
{
const
{
ctx
}
=
this
;
ctx
.
logger
.
info
(
'in logic'
);
// const accessToken = await this.getAccessToken();
const
url
=
`http://221.194.132.83:7780/paas/Interface/
${
accessToken
}
/CallIn`
;
const
lastOne
=
await
ctx
.
prometheusModel
.
HuayunPaasCallin
.
findOne
({
order
:
[[
'id'
,
'desc'
]]
});
const
start
=
0
;
...
...
@@ -66,6 +74,37 @@ class HuaYunPaas extends Subscription {
}
async
callOut
(
accessToken
)
{
const
{
ctx
}
=
this
;
ctx
.
logger
.
info
(
'in logic'
);
// const accessToken = await this.getAccessToken();
const
url
=
`http://221.194.132.83:7780/paas/Interface/
${
accessToken
}
/CallOut`
;
const
lastOne
=
await
ctx
.
prometheusModel
.
HuayunPaasCallOut
.
findOne
({
order
:
[[
'id'
,
'desc'
]]
});
const
start
=
0
;
const
limit
=
10000
;
let
start_time
=
moment
().
add
(
-
1
,
'days'
).
format
(
'YYYY-MM-DD HH:mm:ss'
);
const
now_time
=
moment
().
format
(
'YYYY-MM-DD HH:mm:ss'
);
if
(
lastOne
&&
lastOne
.
end_time
)
{
start_time
=
lastOne
.
end_time
;
}
ctx
.
logger
.
info
(
JSON
.
stringify
({
start_time
,
now_time
,
start
,
limit
}));
const
result
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
300000
,
data
:
{
start_time
,
end_time
:
now_time
,
start
,
limit
}
});
const
ret
=
result
.
data
;
// ctx.logger.info(JSON.stringify({ ret }));
ctx
.
logger
.
info
(
'get result'
);
if
(
ret
.
status
!=
0
||
!
ret
.
message
||
ret
.
count
==
0
)
{
return
;
}
ctx
.
logger
.
info
(
'in add'
);
const
message
=
ret
.
message
;
const
list
=
message
.
data
;
ctx
.
logger
.
info
(
message
.
count
);
const
insert_data
=
await
this
.
format
(
list
);
await
ctx
.
prometheusModel
.
HuayunPaasCallOut
.
bulkCreate
(
insert_data
,
{
ignoreDuplicates
:
true
});
}
async
getAccessToken
()
{
const
{
ctx
}
=
this
;
...
...
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