Commit 94616161 Harvey

no message

1 个父辈 06fae2c8
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
......@@ -4,8 +4,8 @@ exports.JobExecutor = void 0;
class JobExecutor {
jobHandlers = new Map();
constructor(opts) {
if (opts.frpcPath && opts.frpcConfigPath) {
require("./xxl-job/frpc").createFrpc(opts.frpcPath, opts.frpcConfigPath);
if (opts.frpcConfigPath) {
require("./xxl-job/frpc").createFrpc(opts.frpcConfigPath);
}
new (require("./xxl-job/index").XxlJobExecutor)(opts.xxlJob, this.jobHandlers).applyMiddleware({
app: opts.app,
......
......@@ -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);
......
"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() {
......
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
{
"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"
......
......@@ -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.frpcPath && opts.frpcConfigPath) {
require("./xxl-job/frpc").createFrpc(opts.frpcPath, opts.frpcConfigPath);
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 {
......
......@@ -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
};
......
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!