XXL-JOB golang executor is a standalone http server which manages the connection with XXL-JOB server.
The default port is 9999. It registers itself as a node in XXL-JOB server, listens and handles the calls from XXL-JOB server.
A golang executor can run multiple jobs concurrently, but each job is run in serial mode, which is strictly following the design pattern of XXL-JOB:
XXL-JOB的不同任务之间并行调度、并行执行。 XXL-JOB的单个任务,针对多个执行器是并行运行的,针对单个执行器是串行执行的。同时支持任务终止。
See 5.4.5 并行调度
go version >= 1.16
go get -u github.com/hyperjiang/xxljob
import "github.com/hyperjiang/xxljob"
const (
appName = "xxl-job-executor-sample"
accessToken = "default_token"
host = "localhost:8080/xxl-job-admin"
demoHandler = "demoJobHandler"
)
e := xxljob.NewExecutor(
xxljob.WithAppName(appName),
xxljob.WithAccessToken(accessToken),
xxljob.WithHost(host),
)
// start in goroutine
go e.Start()
Job handlers are functions that implement xxljob.JobHandler
(that is func(ctx context.Context, param xxljob.JobParam) error
).
e.AddJobHandler(demoHandler, func(ctx context.Context, param xxljob.JobParam) error {
fmt.Println(param.Params)
return nil
})
e.Stop()