Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
Harvey
/
job-executor
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 94616161
由
Harvey
编写于
2025-05-15 16:10:39 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
no message
1 个父辈
06fae2c8
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
73 行增加
和
37 行删除
README.md
build/index.js
build/test.js
build/xxl-job/frpc.js
frp/frpc_localhost1.toml
package.json
src/index.ts
src/test.ts
src/xxl-job/frpc.ts
README.md
查看文件 @
9461616
http://xxljob.ydniu.com/xxl-job-admin/
admin aolei@ydniu@Harvey
https://git.ydniu.cn/zhanghw/job-
ydn-zq
git@git.ydniu.cn:zhanghw/job-
ydn-zq
.git
https://git.ydniu.cn/zhanghw/job-
executor
git@git.ydniu.cn:zhanghw/job-
executor
.git
启动项目需看配置
1.
config(里面有备注)
2.
frp/frpc.toml
remotePort:注意代理服务器目前只开放 17001-17010端口(每个客户端启动建议使用不同的端口)
1.
package.json配置
需要新增任务
请写在bl目录下和 job目录下 具体参考(/job/sxjx/index.ts)
\ No newline at end of file
"dependencies": {
"job-executor": "git+http://git.ydniu.cn/zhanghw/job-executor.git#1.0.1"
},
frpc配置
serverAddr = "118.89.26.241"
serverPort = 17000
auth.token="aolei@harvey"
[
[proxies
]
]
name = "test-tcp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 8088
remotePort = 17001
2.
使用案列
import
*
as express from "express";
import { JobExecutor } from "job-executor";
import
*
as path from "path";
const config = {
app: express().use(require('body-parser').json()),
appDomain: "http://10.0.1.92:17001/",
port: 8088,
xxlJob: {
executorKey: "job-ydn-zq", // 注:开发环境建议加后缀区分
scheduleCenterUrl: "http://xxljob.ydniu.com/xxl-job-admin",
accessToken: "default_token",
jobLogPath: "logs/job",
enableDebugLog: false,
},
frpcPath: path.join(process.cwd(), 'frp/frpc'), //根目录下文件夹frp中的frpc
frpcConfigPath: path.join(process.cwd(), 'frp/frpc.toml') //根目录下文件夹frp中的frpc.toml
};
var jobExecutor = new JobExecutor(config);
//任务注册
jobExecutor.register("demoJobHandler", async (args) => {
for (let i = 1; i < 10; i++) {
await new Promise((resolve, reject) => {
setTimeout(resolve, 888);
})
}
return { result: 'return value' };
})
\ No newline at end of file
build/index.js
查看文件 @
9461616
...
...
@@ -4,8 +4,8 @@ exports.JobExecutor = void 0;
class
JobExecutor
{
jobHandlers
=
new
Map
();
constructor
(
opts
)
{
if
(
opts
.
frpc
Path
&&
opts
.
frpc
ConfigPath
)
{
require
(
"./xxl-job/frpc"
).
createFrpc
(
opts
.
frpc
Path
,
opts
.
frpc
ConfigPath
);
if
(
opts
.
frpcConfigPath
)
{
require
(
"./xxl-job/frpc"
).
createFrpc
(
opts
.
frpcConfigPath
);
}
new
(
require
(
"./xxl-job/index"
).
XxlJobExecutor
)(
opts
.
xxlJob
,
this
.
jobHandlers
).
applyMiddleware
({
app
:
opts
.
app
,
...
...
build/test.js
查看文件 @
9461616
...
...
@@ -14,7 +14,6 @@ const config = {
jobLogPath
:
"logs/job"
,
enableDebugLog
:
false
,
},
frpcPath
:
path
.
join
(
process
.
cwd
(),
'frp/frpc'
),
frpcConfigPath
:
path
.
join
(
process
.
cwd
(),
'frp/frpc.toml'
)
};
var
jobExecutor
=
new
index_1
.
JobExecutor
(
config
);
...
...
build/xxl-job/frpc.js
查看文件 @
9461616
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
createFrpc
=
createFrpc
;
function
createFrpc
(
frpcPath
,
configPath
)
{
function
createFrpc
(
configPath
)
{
const
{
spawn
}
=
require
(
"child_process"
);
const
path
=
require
(
'path'
);
console
.
log
(
"启动 frpc ..."
);
const
frpc
=
spawn
(
frpcPath
,
[
"-c"
,
configPath
],
{
const
frpc
=
spawn
(
path
.
join
(
__dirname
,
'..'
,
'..'
,
'frp'
,
'frpc'
)
,
[
"-c"
,
configPath
],
{
stdio
:
"inherit"
,
});
function
cleanup
()
{
...
...
frp/frpc_localhost1.toml
deleted
100644 → 0
查看文件 @
06fae2c
serverAddr
=
"118.89.26.241"
serverPort
=
17000
auth.token
=
"aolei@harvey"
[[proxies]]
name
=
"test-tcp"
type
=
"tcp"
localIP
=
"127.0.0.1"
localPort
=
8088
remotePort
=
17002
\ No newline at end of file
package.json
查看文件 @
9461616
{
"name"
:
"job-executor"
,
"version"
:
"1.0.1"
,
"description"
:
""
,
"description"
:
"
xxl-job execution framework for nodejs
"
,
"main"
:
"build/index.js"
,
"scripts"
:
{
"start"
:
"node ./build/index.js"
,
"watch"
:
"tsc -w"
,
"compile"
:
"tsc"
},
"author"
:
""
,
"author"
:
"
harvey
"
,
"license"
:
"ISC"
,
"dependencies"
:
{
"axios"
:
"^1.9.0"
...
...
src/index.ts
查看文件 @
9461616
...
...
@@ -19,15 +19,13 @@ interface XxlJobConfig {
*/
interface
JobExecutorOptions
{
/** Express/Koa 应用实例 */
app
:
any
;
// Express.Application | Koa.Application;
app
:
any
;
// Express.Application | Koa.Application;
/** 应用对外访问的域名(用于回调) */
appDomain
:
string
;
/** 应用监听端口 */
port
:
number
;
/** XXL-JOB 核心配置 */
xxlJob
:
XxlJobConfig
;
/** frpc 客户端路径(可选) */
frpcPath
?:
string
;
/** frpc 配置文件路径(可选) */
frpcConfigPath
?:
string
;
}
...
...
@@ -43,8 +41,8 @@ export class JobExecutor {
constructor
(
opts
:
JobExecutorOptions
)
{
// 初始化 frpc 内网穿透(如果配置存在)
if
(
opts
.
frpc
Path
&&
opts
.
frpc
ConfigPath
)
{
require
(
"./xxl-job/frpc"
).
createFrpc
(
opts
.
frpc
Path
,
opts
.
frpc
ConfigPath
);
if
(
opts
.
frpcConfigPath
)
{
require
(
"./xxl-job/frpc"
).
createFrpc
(
opts
.
frpcConfigPath
);
}
// 连接 XXL-JOB 调度中心
...
...
@@ -80,7 +78,7 @@ export class JobExecutor {
}
console
.
log
(
`[XXL-JOB] Job "
${
jobName
}
" registered`
);
// 包装 handler
this
.
jobHandlers
.
set
(
jobName
,
async
(...
args
:
any
[])
=>
{
try
{
...
...
src/test.ts
查看文件 @
9461616
...
...
@@ -13,7 +13,6 @@ const config = {
jobLogPath
:
"logs/job"
,
enableDebugLog
:
false
,
},
frpcPath
:
path
.
join
(
process
.
cwd
(),
'frp/frpc'
),
//根目录下文件夹frp中的frpc
frpcConfigPath
:
path
.
join
(
process
.
cwd
(),
'frp/frpc.toml'
)
//根目录下文件夹frp中的frpc.toml
};
...
...
src/xxl-job/frpc.ts
查看文件 @
9461616
export
function
createFrpc
(
frpcPath
:
string
,
configPath
:
string
)
{
const
{
spawn
}
=
require
(
"child_process"
);
console
.
log
(
"启动 frpc ..."
);
export
function
createFrpc
(
configPath
:
string
)
{
const
{
spawn
}
=
require
(
"child_process"
)
const
path
=
require
(
'path'
)
console
.
log
(
"启动 frpc ..."
)
// 1. 启动 frpc 进程
const
frpc
=
spawn
(
frpcPath
,
[
"-c"
,
configPath
],
{
const
frpc
=
spawn
(
path
.
join
(
__dirname
,
'..'
,
'..'
,
'frp'
,
'frpc'
)
,
[
"-c"
,
configPath
],
{
stdio
:
"inherit"
,
// 共享输入输出
});
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论