go_xxljob_excutor

package module
v0.0.0-...-7eb9a9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2022 License: GPL-2.0 Imports: 9 Imported by: 0

README

gitee.com/youbeiwuhuan/go-xxljob-executor

介绍

go实现的xxljob执行器,仅支持BEAN模式执行器,不支持GlueType模式。

分支说明

dev-XXX 分支 对应xxl-job-XXX 版本的调度器。当前正在开发 dev2.1.2 分支,对应官方tag 2.1.2. xxl-job 2.0以下版本太老就不适配了

分支 描述 状态
master 主分支 代码和dev2.3.0 相同
dev2.3.0 对应Java版执行器2.3.0 开发完成,与xxl-job-2.3.0后台联调测试通过
dev2.1.2 对应Java版执行器2.1.2 开发完成,与xxl-job-2.1.2后台联调测试通过 (2.1.1 联调也通过)
dev2.3.0 分支(仅引入了web包gin和日志包zap,其他都是go原生包)

除了不支持GlueType模式任务外(个人觉得go的执行器没必要实现GlueType模式任务,要用GlueType模式任务直接用java版执行器更合适), 基本实现了所有的执行器功能。几乎是将对着java执行器代码用go翻译了一遍。因为本人现在的饭碗还是java,对go还是不熟练,代码肯定有WTF,请谅解!

使用说明

示例说明 进入main 目录下,修改example.go,运行即可

image

导包

go get https://gitee.com/youbeiwuhuan/go-xxljob-executor

代码示例
package hanlder

import (
	. "gitee.com/youbeiwuhuan/go-xxljob-executor/biz/model"
	. "gitee.com/youbeiwuhuan/go-xxljob-executor/global"
	"gitee.com/youbeiwuhuan/go-xxljob-executor/handler"
	"gitee.com/youbeiwuhuan/go-xxljob-executor/tools"
	"time"
)

type HelloJobHandler struct {
}

func (t *HelloJobHandler) Init(context handler.JobContext, xxlLogger *tools.XxlJobFileLogger) {

	Logger.Info("----------HelloJobHandler----Init------------------------" + context.String())

}
func (t *HelloJobHandler) Destroy(context handler.JobContext, xxlLogger *tools.XxlJobFileLogger) {
	Logger.Info("----------HelloJobHandler----Destroy------------------------" + context.String())
}
func (t *HelloJobHandler) Execute(param string, context handler.JobContext, xxlLogger *tools.XxlJobFileLogger) ReturnT {
	Logger.Info("----------HelloJobHandler----Execute------------------------" + context.String())
	time.Sleep(5 * time.Second)
	xxlLogger.Log("----------HelloJobHandler----Execute------------------------" + context.String())

	return ReturnT{Code: SUCCESS_CODE}
}

package main

import (
	"fmt"
	. "gitee.com/youbeiwuhuan/go-xxljob-executor"
	"gitee.com/youbeiwuhuan/go-xxljob-executor/main/handler"
	"time"
)

func main() {
	e := NewXxljobExcutor("http://127.0.0.1:8080/xxl-job-admin",
		"",
		"gitee.com/youbeiwuhuan/go-xxljob-executor",

		"http://127.0.0.1:9222",
		"127.0.0.1",
		9222,
		"D:/tmp/gitee.com/youbeiwuhuan/go-xxljob-executor",
		60)

	e.AddJobHandler("HelloJobHandler", &handler.HelloJobHandler{})

	e.Start()

	for {
		time.Sleep(time.Duration(30) * time.Second)
		fmt.Println("----------example run----------------------------")
	}

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitAdminBizList

func InitAdminBizList(adminAddresses string, accessToken string) []*client.AdminBizClient

func InitBizServer

func InitBizServer(ip string, port int32, accessToken string, triggerCallback *proccess.TriggerCallbackProccessor) *server.ExecutorBizServer

func InitExecutorRegistryProccessor

func InitExecutorRegistryProccessor(appname string, address string) *proccess.ExecutorRegistryProccessor

func InitJobLogFileCleanProccessor

func InitJobLogFileCleanProccessor(logRetentionDays int32, xxlLogPath string) *proccess.JobLogFileCleanProccessor

func InitTriggerCallbackProccessor

func InitTriggerCallbackProccessor() *proccess.TriggerCallbackProccessor

func InitZapLogger

func InitZapLogger(logPath string) *zap.Logger

---------------- 一下是初始化方法-------------------------------------------------------------------------------------------------------------------------------------------------------------

Types

type XxljobExcutor

type XxljobExcutor struct {
	// contains filtered or unexported fields
}

func NewXxljobExcutor

func NewXxljobExcutor(
	adminAddresses string,
	accessToken string,
	appname string,

	address string,
	ip string,
	port int32,
	logPath string,
	logRetentionDays int32) *XxljobExcutor

func (*XxljobExcutor) AddJobHandler

func (xe *XxljobExcutor) AddJobHandler(handlerName string, handler handler.IJobHandler)
添加IJobHandler

@auth Frank Fan @param handlerName string @param handler IJobHandler @return

func (*XxljobExcutor) Destroy

func (xe *XxljobExcutor) Destroy()

func (*XxljobExcutor) Start

func (xe *XxljobExcutor) Start()

Directories

Path Synopsis
biz
enums
zap
@Title 请填写文件名称(需要改) @Description 请填写文件描述(需要改) @Author 请填写自己的真是姓名(需要改) 2021/6/27 0:06 @Update 请填写自己的真是姓名(需要改) 2021/6/27 0:06
@Title 请填写文件名称(需要改) @Description 请填写文件描述(需要改) @Author 请填写自己的真是姓名(需要改) 2021/6/27 0:06 @Update 请填写自己的真是姓名(需要改) 2021/6/27 0:06
utils

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL