Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
Harvey
/
job-executor
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 6471b6b5
由
Harvey
编写于
2025-04-28 17:35:07 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
no message
1 个父辈
ee207e6a
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
41 行增加
和
56 行删除
build/index.js
build/xxl_job/executor.js
build/xxl_job/index.js
config/config.js
src/index.ts
src/xxl_job/executor.ts
src/xxl_job/index.ts
build/index.js
查看文件 @
6471b6b
...
@@ -2,9 +2,10 @@
...
@@ -2,9 +2,10 @@
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
express
=
require
(
"express"
);
const
express
=
require
(
"express"
);
const
config
=
require
(
'../config/config.js'
);
const
config
=
require
(
'../config/config.js'
);
console
.
log
(
config
);
const
app
=
express
();
const
app
=
express
();
app
.
use
(
require
(
'body-parser'
).
json
());
app
.
use
(
require
(
'body-parser'
).
json
());
new
(
require
(
"./xxl_job/index"
).
XxlJobExecutor
)(
config
.
xxl_job
,
require
(
'./job'
).
job_handlers
).
applyMiddleware
({
app
,
domain
:
config
.
app_domain
,
path
:
''
});
new
(
require
(
"./xxl_job/index"
).
XxlJobExecutor
)(
config
.
xxl_job
,
require
(
'./job'
).
job_handlers
).
applyMiddleware
({
app
,
domain
:
config
.
app_domain
});
app
.
listen
(
config
.
port
,
()
=>
{
app
.
listen
(
config
.
port
,
()
=>
{
console
.
log
(
`job-ydn-zq app listening on port
${
config
.
port
}
`
);
console
.
log
(
`job-ydn-zq app listening on port
${
config
.
port
}
`
);
});
});
...
...
build/xxl_job/executor.js
查看文件 @
6471b6b
...
@@ -30,24 +30,14 @@ class Executor {
...
@@ -30,24 +30,14 @@ class Executor {
/**
/**
* 应用执行器中间件
* 应用执行器中间件
* @param {*} app
* @param {*} app
* @param {string} app_domain
* @param {string} domain
* @param {string} uri
*/
*/
applyMiddleware
({
app
,
app_domain
,
uri
})
{
applyMiddleware
({
app
,
domain
})
{
this
.
executorUrl
=
domain
;
const
express
=
require
(
'express'
);
const
express
=
require
(
'express'
);
var
router
=
new
express
.
Router
();
var
router
=
new
express
.
Router
();
this
.
initRouter
(
router
,
uri
);
//请求认证
this
.
addJobRoutes
(
router
,
uri
);
router
.
use
(
async
(
req
,
res
,
next
)
=>
{
app
.
use
(
router
);
this
.
executorUrl
=
(
app_domain
||
'http://192.168.31.251:8088'
)
+
uri
;
}
/**
* 添加xxl-job相关的路由,供调度中心访问
* @param {express.Router} router
* @param {string} baseUri
*/
initRouter
(
router
,
uri
)
{
router
.
use
(
uri
,
async
(
req
,
res
,
next
)
=>
{
res
.
status
(
200
);
res
.
status
(
200
);
const
token
=
req
.
headers
&&
req
.
headers
[
'xxl-job-access-token'
];
const
token
=
req
.
headers
&&
req
.
headers
[
'xxl-job-access-token'
];
if
(
!!
this
.
accessToken
&&
this
.
accessToken
!==
token
)
{
if
(
!!
this
.
accessToken
&&
this
.
accessToken
!==
token
)
{
...
@@ -60,26 +50,28 @@ class Executor {
...
@@ -60,26 +50,28 @@ class Executor {
}
}
next
();
next
();
});
});
this
.
addJobRoutes
(
router
);
app
.
use
(
router
);
}
}
/**
/**
* 添加xxl-job相关的路由,供调度中心访问
* 添加xxl-job相关的路由,供调度中心访问
* @param {express.Router} router
* @param {express.Router} router
* @param {string} baseUri
* @param {string} baseUri
*/
*/
addJobRoutes
(
router
,
baseUri
)
{
addJobRoutes
(
router
)
{
router
.
post
(
`
${
baseUri
}
/beat`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/beat`
,
async
(
req
,
res
,
next
)
=>
{
res
.
send
(
this
.
beat
());
res
.
send
(
this
.
beat
());
});
});
router
.
post
(
`
${
baseUri
}
/idleBeat`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/idleBeat`
,
async
(
req
,
res
,
next
)
=>
{
res
.
send
(
this
.
idleBeat
(
req
.
body
.
jobId
||
-
1
));
res
.
send
(
this
.
idleBeat
(
req
.
body
.
jobId
||
-
1
));
});
});
router
.
post
(
`
${
baseUri
}
/run`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/run`
,
async
(
req
,
res
,
next
)
=>
{
res
.
send
(
this
.
run
(
req
.
body
||
{}));
res
.
send
(
this
.
run
(
req
.
body
||
{}));
});
});
router
.
post
(
`
${
baseUri
}
/kill`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/kill`
,
async
(
req
,
res
,
next
)
=>
{
res
.
send
(
this
.
killJob
(
req
.
body
.
jobId
||
-
1
));
res
.
send
(
this
.
killJob
(
req
.
body
.
jobId
||
-
1
));
});
});
router
.
post
(
`
${
baseUri
}
/log`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/log`
,
async
(
req
,
res
,
next
)
=>
{
const
{
logDateTim
,
logId
,
fromLineNum
}
=
req
.
body
||
{};
const
{
logDateTim
,
logId
,
fromLineNum
}
=
req
.
body
||
{};
const
data
=
await
this
.
readLog
(
logDateTim
,
logId
,
fromLineNum
);
const
data
=
await
this
.
readLog
(
logDateTim
,
logId
,
fromLineNum
);
res
.
send
(
data
);
res
.
send
(
data
);
...
...
build/xxl_job/index.js
查看文件 @
6471b6b
...
@@ -22,10 +22,9 @@ class XxlJobExecutor {
...
@@ -22,10 +22,9 @@ class XxlJobExecutor {
* @param {Object} args
* @param {Object} args
* @param {any} args.app 执行器server, express
* @param {any} args.app 执行器server, express
* @param {string} args.appDomain 执行器 server 地址
* @param {string} args.appDomain 执行器 server 地址
* @param {string} args.path 执行器挂载的 uri 路径
*/
*/
applyMiddleware
({
app
,
domain
,
path
})
{
applyMiddleware
({
app
,
domain
})
{
this
.
executor
.
applyMiddleware
({
app
,
domain
,
path
});
this
.
executor
.
applyMiddleware
({
app
,
domain
});
const
registry
=
this
.
executor
.
registry
.
bind
(
this
.
executor
);
const
registry
=
this
.
executor
.
registry
.
bind
(
this
.
executor
);
registry
()
&&
(
this
.
registryInterval
=
setInterval
(
registry
,
30000
));
registry
()
&&
(
this
.
registryInterval
=
setInterval
(
registry
,
30000
));
}
}
...
...
config/config.js
查看文件 @
6471b6b
...
@@ -8,7 +8,7 @@ try {
...
@@ -8,7 +8,7 @@ try {
// 执行器AppName,在调度中心配置执行器时使用
// 执行器AppName,在调度中心配置执行器时使用
XXL_JOB_EXECUTOR_KEY
:
"executor-job-ydn-zq"
,
XXL_JOB_EXECUTOR_KEY
:
"executor-job-ydn-zq"
,
// 调度中心地址
// 调度中心地址
XXL_JOB_SCHEDULE_CENTER_URL
:
"http://
xxljob.ydniu.com
/xxl-job-admin"
,
XXL_JOB_SCHEDULE_CENTER_URL
:
"http://
192.168.2.168:8080
/xxl-job-admin"
,
// 调度中心设置的请求令牌,调度中心和执行器都会进行校验,双方AccessToken匹配才允许通讯
// 调度中心设置的请求令牌,调度中心和执行器都会进行校验,双方AccessToken匹配才允许通讯
XXL_JOB_ACCESS_TOKEN
:
"default_token"
,
XXL_JOB_ACCESS_TOKEN
:
"default_token"
,
// 任务执行日志的存储路径
// 任务执行日志的存储路径
...
@@ -20,7 +20,7 @@ try {
...
@@ -20,7 +20,7 @@ try {
port
:
8088
,
port
:
8088
,
// 前端地址
// 前端地址
app_domain
:
"http://[2408:8352:602:1100:1c8a:80f5:da47:66ef]:8088"
,
app_domain
:
"http://[2408:8352:602:1100:1c8a:80f5:da47:66ef]:8088
/
"
,
};
};
}
}
...
...
src/index.ts
查看文件 @
6471b6b
import
*
as
express
from
'express'
import
*
as
express
from
'express'
const
config
=
require
(
'../config/config.js'
)
const
config
=
require
(
'../config/config.js'
)
console
.
log
(
config
)
const
app
=
express
()
const
app
=
express
()
app
.
use
(
require
(
'body-parser'
).
json
())
app
.
use
(
require
(
'body-parser'
).
json
())
new
(
require
(
"./xxl_job/index"
).
XxlJobExecutor
)(
new
(
require
(
"./xxl_job/index"
).
XxlJobExecutor
)(
config
.
xxl_job
,
config
.
xxl_job
,
require
(
'./job'
).
job_handlers
require
(
'./job'
).
job_handlers
).
applyMiddleware
({
app
,
domain
:
config
.
app_domain
,
path
:
''
})
).
applyMiddleware
({
app
,
domain
:
config
.
app_domain
})
app
.
listen
(
config
.
port
,
()
=>
{
app
.
listen
(
config
.
port
,
()
=>
{
console
.
log
(
`job-ydn-zq app listening on port
${
config
.
port
}
`
)
console
.
log
(
`job-ydn-zq app listening on port
${
config
.
port
}
`
)
...
...
src/xxl_job/executor.ts
查看文件 @
6471b6b
...
@@ -32,29 +32,15 @@ export class Executor {
...
@@ -32,29 +32,15 @@ export class Executor {
/**
/**
* 应用执行器中间件
* 应用执行器中间件
* @param {*} app
* @param {*} app
* @param {string} app_domain
* @param {string} domain
* @param {string} uri
*/
*/
applyMiddleware
({
app
,
app_domain
,
uri
})
{
applyMiddleware
({
app
,
domain
})
{
this
.
executorUrl
=
domain
const
express
=
require
(
'express'
)
const
express
=
require
(
'express'
)
var
router
=
new
express
.
Router
()
var
router
=
new
express
.
Router
()
this
.
initRouter
(
router
,
uri
)
this
.
addJobRoutes
(
router
,
uri
)
app
.
use
(
router
)
//请求认证
router
.
use
(
async
(
req
,
res
,
next
)
=>
{
this
.
executorUrl
=
(
app_domain
||
'http://192.168.31.251:8088'
)
+
uri
}
/**
* 添加xxl-job相关的路由,供调度中心访问
* @param {express.Router} router
* @param {string} baseUri
*/
initRouter
(
router
:
any
,
uri
:
string
)
{
router
.
use
(
uri
,
async
(
req
,
res
,
next
)
=>
{
res
.
status
(
200
)
res
.
status
(
200
)
const
token
=
req
.
headers
&&
req
.
headers
[
'xxl-job-access-token'
]
const
token
=
req
.
headers
&&
req
.
headers
[
'xxl-job-access-token'
]
...
@@ -72,6 +58,12 @@ export class Executor {
...
@@ -72,6 +58,12 @@ export class Executor {
next
()
next
()
})
})
this
.
addJobRoutes
(
router
)
app
.
use
(
router
)
}
}
/**
/**
...
@@ -79,24 +71,24 @@ export class Executor {
...
@@ -79,24 +71,24 @@ export class Executor {
* @param {express.Router} router
* @param {express.Router} router
* @param {string} baseUri
* @param {string} baseUri
*/
*/
addJobRoutes
(
router
,
baseUri
)
{
addJobRoutes
(
router
)
{
router
.
post
(
`
${
baseUri
}
/beat`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/beat`
,
async
(
req
,
res
,
next
)
=>
{
res
.
send
(
this
.
beat
())
res
.
send
(
this
.
beat
())
})
})
router
.
post
(
`
${
baseUri
}
/idleBeat`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/idleBeat`
,
async
(
req
,
res
,
next
)
=>
{
res
.
send
(
this
.
idleBeat
(
req
.
body
.
jobId
||
-
1
))
res
.
send
(
this
.
idleBeat
(
req
.
body
.
jobId
||
-
1
))
})
})
router
.
post
(
`
${
baseUri
}
/run`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/run`
,
async
(
req
,
res
,
next
)
=>
{
res
.
send
(
this
.
run
(
req
.
body
||
{}))
res
.
send
(
this
.
run
(
req
.
body
||
{}))
})
})
router
.
post
(
`
${
baseUri
}
/kill`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/kill`
,
async
(
req
,
res
,
next
)
=>
{
res
.
send
(
this
.
killJob
(
req
.
body
.
jobId
||
-
1
))
res
.
send
(
this
.
killJob
(
req
.
body
.
jobId
||
-
1
))
})
})
router
.
post
(
`
${
baseUri
}
/log`
,
async
(
req
,
res
,
next
)
=>
{
router
.
post
(
`/log`
,
async
(
req
,
res
,
next
)
=>
{
const
{
logDateTim
,
logId
,
fromLineNum
}
=
req
.
body
||
{}
const
{
logDateTim
,
logId
,
fromLineNum
}
=
req
.
body
||
{}
const
data
=
await
this
.
readLog
(
logDateTim
,
logId
,
fromLineNum
)
const
data
=
await
this
.
readLog
(
logDateTim
,
logId
,
fromLineNum
)
res
.
send
(
data
)
res
.
send
(
data
)
...
...
src/xxl_job/index.ts
查看文件 @
6471b6b
...
@@ -29,10 +29,9 @@ export class XxlJobExecutor {
...
@@ -29,10 +29,9 @@ export class XxlJobExecutor {
* @param {Object} args
* @param {Object} args
* @param {any} args.app 执行器server, express
* @param {any} args.app 执行器server, express
* @param {string} args.appDomain 执行器 server 地址
* @param {string} args.appDomain 执行器 server 地址
* @param {string} args.path 执行器挂载的 uri 路径
*/
*/
public
applyMiddleware
({
app
,
domain
,
path
})
{
public
applyMiddleware
({
app
,
domain
})
{
this
.
executor
.
applyMiddleware
({
app
,
domain
,
path
})
this
.
executor
.
applyMiddleware
({
app
,
domain
})
const
registry
=
this
.
executor
.
registry
.
bind
(
this
.
executor
)
const
registry
=
this
.
executor
.
registry
.
bind
(
this
.
executor
)
registry
()
&&
(
this
.
registryInterval
=
setInterval
(
registry
,
30000
))
registry
()
&&
(
this
.
registryInterval
=
setInterval
(
registry
,
30000
))
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论