Commit 94616161 Harvey

no message

1 个父辈 06fae2c8
http://xxljob.ydniu.com/xxl-job-admin/ http://xxljob.ydniu.com/xxl-job-admin/
admin aolei@ydniu@Harvey admin aolei@ydniu@Harvey
https://git.ydniu.cn/zhanghw/job-ydn-zq https://git.ydniu.cn/zhanghw/job-executor
git@git.ydniu.cn:zhanghw/job-ydn-zq.git git@git.ydniu.cn:zhanghw/job-executor.git
启动项目需看配置
1.config(里面有备注)
2.frp/frpc.toml 1.package.json配置
remotePort:注意代理服务器目前只开放 17001-17010端口(每个客户端启动建议使用不同的端口)
需要新增任务
请写在bl目录下和 job目录下 具体参考(/job/sxjx/index.ts)
\ No newline at end of file \ 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 \ No newline at end of file
...@@ -4,8 +4,8 @@ exports.JobExecutor = void 0; ...@@ -4,8 +4,8 @@ exports.JobExecutor = void 0;
class JobExecutor { class JobExecutor {
jobHandlers = new Map(); jobHandlers = new Map();
constructor(opts) { constructor(opts) {
if (opts.frpcPath && opts.frpcConfigPath) { if (opts.frpcConfigPath) {
require("./xxl-job/frpc").createFrpc(opts.frpcPath, opts.frpcConfigPath); require("./xxl-job/frpc").createFrpc(opts.frpcConfigPath);
} }
new (require("./xxl-job/index").XxlJobExecutor)(opts.xxlJob, this.jobHandlers).applyMiddleware({ new (require("./xxl-job/index").XxlJobExecutor)(opts.xxlJob, this.jobHandlers).applyMiddleware({
app: opts.app, app: opts.app,
......
...@@ -14,7 +14,6 @@ const config = { ...@@ -14,7 +14,6 @@ const config = {
jobLogPath: "logs/job", jobLogPath: "logs/job",
enableDebugLog: false, enableDebugLog: false,
}, },
frpcPath: path.join(process.cwd(), 'frp/frpc'),
frpcConfigPath: path.join(process.cwd(), 'frp/frpc.toml') frpcConfigPath: path.join(process.cwd(), 'frp/frpc.toml')
}; };
var jobExecutor = new index_1.JobExecutor(config); var jobExecutor = new index_1.JobExecutor(config);
......
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.createFrpc = createFrpc; exports.createFrpc = createFrpc;
function createFrpc(frpcPath, configPath) { function createFrpc(configPath) {
const { spawn } = require("child_process"); const { spawn } = require("child_process");
const path = require('path');
console.log("启动 frpc ..."); console.log("启动 frpc ...");
const frpc = spawn(frpcPath, ["-c", configPath], { const frpc = spawn(path.join(__dirname, '..', '..', 'frp', 'frpc'), ["-c", configPath], {
stdio: "inherit", stdio: "inherit",
}); });
function cleanup() { function cleanup() {
......
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 \ No newline at end of file
{ {
"name": "job-executor", "name": "job-executor",
"version": "1.0.1", "version": "1.0.1",
"description": "", "description": "xxl-job execution framework for nodejs",
"main": "build/index.js", "main": "build/index.js",
"scripts": { "scripts": {
"start": "node ./build/index.js", "start": "node ./build/index.js",
"watch": "tsc -w", "watch": "tsc -w",
"compile": "tsc" "compile": "tsc"
}, },
"author": "", "author": "harvey",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^1.9.0" "axios": "^1.9.0"
......
...@@ -19,15 +19,13 @@ interface XxlJobConfig { ...@@ -19,15 +19,13 @@ interface XxlJobConfig {
*/ */
interface JobExecutorOptions { interface JobExecutorOptions {
/** Express/Koa 应用实例 */ /** Express/Koa 应用实例 */
app:any; // Express.Application | Koa.Application; app: any; // Express.Application | Koa.Application;
/** 应用对外访问的域名(用于回调) */ /** 应用对外访问的域名(用于回调) */
appDomain: string; appDomain: string;
/** 应用监听端口 */ /** 应用监听端口 */
port: number; port: number;
/** XXL-JOB 核心配置 */ /** XXL-JOB 核心配置 */
xxlJob: XxlJobConfig; xxlJob: XxlJobConfig;
/** frpc 客户端路径(可选) */
frpcPath?: string;
/** frpc 配置文件路径(可选) */ /** frpc 配置文件路径(可选) */
frpcConfigPath?: string; frpcConfigPath?: string;
} }
...@@ -43,8 +41,8 @@ export class JobExecutor { ...@@ -43,8 +41,8 @@ export class JobExecutor {
constructor(opts: JobExecutorOptions) { constructor(opts: JobExecutorOptions) {
// 初始化 frpc 内网穿透(如果配置存在) // 初始化 frpc 内网穿透(如果配置存在)
if (opts.frpcPath && opts.frpcConfigPath) { if (opts.frpcConfigPath) {
require("./xxl-job/frpc").createFrpc(opts.frpcPath, opts.frpcConfigPath); require("./xxl-job/frpc").createFrpc(opts.frpcConfigPath);
} }
// 连接 XXL-JOB 调度中心 // 连接 XXL-JOB 调度中心
......
...@@ -13,7 +13,6 @@ const config = { ...@@ -13,7 +13,6 @@ const config = {
jobLogPath: "logs/job", jobLogPath: "logs/job",
enableDebugLog: false, enableDebugLog: false,
}, },
frpcPath: path.join(process.cwd(), 'frp/frpc'), //根目录下文件夹frp中的frpc
frpcConfigPath: path.join(process.cwd(), 'frp/frpc.toml') //根目录下文件夹frp中的frpc.toml frpcConfigPath: path.join(process.cwd(), 'frp/frpc.toml') //根目录下文件夹frp中的frpc.toml
}; };
......
export function createFrpc(frpcPath: string, configPath: string) { export function createFrpc(configPath: string) {
const { spawn } = require("child_process"); const { spawn } = require("child_process")
const path = require('path')
console.log("启动 frpc ..."); console.log("启动 frpc ...")
// 1. 启动 frpc 进程 // 1. 启动 frpc 进程
const frpc = spawn(frpcPath, ["-c", configPath], { const frpc = spawn(path.join(__dirname, '..', '..', 'frp', 'frpc'), ["-c", configPath], {
stdio: "inherit", // 共享输入输出 stdio: "inherit", // 共享输入输出
}); });
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!