xxl

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 14 Imported by: 2

README

xxl-job client for Golang

Installation

go get github.com/go-xxl/xxl@v0.0.2

Quickstart

package main

import (
	"github.com/go-xxl/xxl"
	"github.com/go-xxl/xxl/admin"
	"github.com/go-xxl/xxl/job"
	"github.com/go-xxl/xxl/server"
	"github.com/go-xxl/xxl/utils"
	"time"
)

func main() {

	//log.SetLog(&CLog{})

	e := xxl.NewExecutor(
		xxl.AdmAdmAddresses("http://192.168.0.104:8080/xxl-job-admin/"),
		xxl.ExecutorIp(utils.GetLocalIp()),
		xxl.ExecutorPort("12345"),
		xxl.RegistryKey("demo-test"),
	)

	e.Job("/demo", func(ctx *server.Context) job.Resp {
		param := ctx.Param

		time.Sleep(time.Second * 30)

		return job.Resp{
			LogID:       param.LogID,
			LogDateTime: time.Now().Unix(),
			HandleCode:  admin.SuccessCode,
			HandleMsg:   "get result",
		}
	})

	e.WithHealthCheck("/health", func(ctx *server.Context) {
		ctx.Success("pong return", "pong")
		return
	})

	e.WithDebug(true)

	e.Run()
}

Tree

.
├── _example
├── admin
├── job
├── log
├── server
├── utils
└── vendor
    └── go.uber.org
        ├── atomic
        ├── multierr
        └── zap
            ├── buffer
            ├── internal
            │   ├── bufferpool
            │   ├── color
            │   └── exit
            └── zapcore

Documentation

Index

Constants

View Source
const (
	DefaultExecutorPort = "9999"
	DefaultRegistryKey  = "golang-jobs"
)
View Source
const (
	GlueTypeBEAN       = "BEAN"
	GlueTypeGROOVY     = "GLUE(Java)"
	GlueTypeSHELL      = "GLUE(Shell)"
	GlueTypePYTHON     = "GLUE(Python)"
	GlueTypePHP        = "GLUE(PHP)"
	GlueTypeNODEJS     = "GLUE(Nodejs)"
	GlueTypePOWERSHELL = "GLUE(PowerShell)"
)
View Source
const (
	SerialExecution = "SERIAL_EXECUTION"
	DiscardLater    = "DISCARD_LATER"
	CoverEarly      = "COVER_EARLY"
)

Variables

This section is empty.

Functions

func IsScript

func IsScript(glueType string) bool

Types

type Executor

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

Executor Executor

func (*Executor) Job

func (e *Executor) Job(handlerName string, handler job.Func)

func (*Executor) Run

func (e *Executor) Run()

Run start job service

func (*Executor) WithDebug

func (e *Executor) WithDebug(debug bool)

WithDebug open pprof

func (*Executor) WithHealthCheck

func (e *Executor) WithHealthCheck(path string, handler server.Handler)

WithHealthCheck ExecutorService's web health check endpoint

func (*Executor) WrapF

func (e *Executor) WrapF(f func(w http.ResponseWriter, r *http.Request)) server.Handler

type ExecutorBiz

type ExecutorBiz struct {
}

func NewExecutorService

func NewExecutorService() *ExecutorBiz

func (*ExecutorBiz) Beat

func (biz *ExecutorBiz) Beat(ctx *server.Context)

Beat check alive

func (*ExecutorBiz) IdleBeat

func (biz *ExecutorBiz) IdleBeat(ctx *server.Context)

IdleBeat check job is alive

func (*ExecutorBiz) Kill

func (biz *ExecutorBiz) Kill(ctx *server.Context)

Kill stop job

func (*ExecutorBiz) Log

func (biz *ExecutorBiz) Log(ctx *server.Context)

Log job log

func (*ExecutorBiz) Run

func (biz *ExecutorBiz) Run(ctx *server.Context)

Run start web service

type HealthFunc

type HealthFunc func(ctx *server.Context)

type JobExecutor

type JobExecutor interface {
	// Job add a job endpoint
	Job(handlerName string, handler job.Func)

	WithHealthCheck(path string, handler server.Handler)

	WithDebug(isDebug bool)

	Run()
}

func NewExecutor

func NewExecutor(opts ...Option) JobExecutor

NewExecutor create a JobExecutor

type LogReq

type LogReq struct {
	LogDateTim  int64 `json:"logDateTim"`
	LogId       int   `json:"logId"`
	FromLineNum int   `json:"fromLineNum"`
}

type LogResp

type LogResp struct {
	FromLineNum int    `json:"fromLineNum"`
	ToLineNum   int    `json:"toLineNum"`
	LogContent  string `json:"logContent"`
	IsEnd       bool   `json:"isEnd"`
}

type Option

type Option func(o *Options)

func AccessToken

func AccessToken(token string) Option

func AdmAdmAddresses

func AdmAdmAddresses(addr ...string) Option

func ExecutorIp

func ExecutorIp(ip string) Option

func ExecutorPort

func ExecutorPort(port string) Option

func RegistryKey

func RegistryKey(registryKey string) Option

type Options

type Options struct {
	AdmAddresses  []string
	AccessToken   string
	Timeout       time.Duration
	ExecutorIp    string
	ExecutorPort  string
	RegistryKey   string
	RegistryValue string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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