liuhaijun e94826ce29 add server
Change-Id: I0760f17f6a01c0121b59fcbfafc666032dbc30af
2024-09-19 09:44:15 +00:00

51 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package data
import (
"fmt"
c "git.inspur.com/sbg-jszt/cfn/cfn-schedule/config"
"git.inspur.com/sbg-jszt/cfn/cfn-schedule/pkg/log"
"github.com/xxl-job/xxl-job-executor-go"
"strconv"
)
var Xxljob xxl.Executor
func initXxlJob() {
if !c.Config.CfnConfig.Enable {
return
}
//初始化执行器
Xxljob = xxl.NewExecutor(
xxl.ServerAddr(c.Config.XxlJob.Url),
xxl.AccessToken(c.Config.XxlJob.Token),
xxl.ExecutorPort(strconv.FormatUint(c.Config.Server.Port, 10)), //默认9999此处要与gin服务启动port必需一至
xxl.RegistryKey("cfn-schedule"), //执行器名称
xxl.SetLogger(&clogger{}), //自定义日志
)
Xxljob.Init()
//设置日志查看handler
Xxljob.LogHandler(customLogHandle)
}
// 自定义日志处理器
func customLogHandle(req *xxl.LogReq) *xxl.LogRes {
return &xxl.LogRes{Code: xxl.SuccessCode, Msg: "", Content: xxl.LogResContent{
FromLineNum: req.FromLineNum,
ToLineNum: 2,
LogContent: "这个是自定义日志handler",
IsEnd: true,
}}
}
// xxl.Logger接口实现
type clogger struct{}
func (l *clogger) Info(format string, a ...interface{}) {
log.Info(fmt.Sprintf("xxl-job日志 - "+format, a...))
}
func (l *clogger) Error(format string, a ...interface{}) {
log.Error(fmt.Sprintf("xxl-job日志 - "+format, a...))
}