All Projects → feixiaobo → go-xxl-job-client

feixiaobo / go-xxl-job-client

Licence: other
xxl-job go client

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-xxl-job-client

Xxl Job
A distributed task scheduling framework.(分布式任务调度平台XXL-JOB)
Stars: ✭ 20,197 (+56002.78%)
Mutual labels:  task, scheduler, glue, xxl-job
Queuer
Queuer is a queue manager, built on top of OperationQueue and Dispatch (aka GCD).
Stars: ✭ 964 (+2577.78%)
Mutual labels:  task, scheduler
Kob
中心化的作业调度系统,定义了任务调度模型,实现了任务调度的统一管理和监控。
Stars: ✭ 393 (+991.67%)
Mutual labels:  task, job-scheduler
Beatserver
Beatserver, a periodic task scheduler for Django 🎵
Stars: ✭ 106 (+194.44%)
Mutual labels:  task, scheduler
Docker Airflow
Docker Apache Airflow
Stars: ✭ 3,375 (+9275%)
Mutual labels:  task, scheduler
chronus
Chronus是360数科技术团队基于阿里开源项目TBSchedule重写的分布式调度。
Stars: ✭ 174 (+383.33%)
Mutual labels:  task, scheduler
Clock
可视化任务调度系统,精简到一个二进制文件 (Web visual task scheduler system , yes ! just one binary solve all the problems !)
Stars: ✭ 86 (+138.89%)
Mutual labels:  task, scheduler
Jobs
jobs 分布式任务调度平台
Stars: ✭ 245 (+580.56%)
Mutual labels:  scheduler, job-scheduler
Chronus
Chronus是360金融技术团队基于阿里开源项目TBSchedule重写的分布式调度。
Stars: ✭ 166 (+361.11%)
Mutual labels:  task, scheduler
Scheduler
Task scheduler for Golang
Stars: ✭ 171 (+375%)
Mutual labels:  task, scheduler
Cloudtask
cloudtask is a distributed task scheduling platform.
Stars: ✭ 173 (+380.56%)
Mutual labels:  task, scheduler
josk
🏃🤖 Scheduler and manager for jobs and tasks in node.js on multi-server and clusters setup
Stars: ✭ 27 (-25%)
Mutual labels:  task, scheduler
linda
Linda is a simple dispatcher library.
Stars: ✭ 12 (-66.67%)
Mutual labels:  task, scheduler
resc
A task orchestrator using redis, written in rust
Stars: ✭ 27 (-25%)
Mutual labels:  task, scheduler
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+436.11%)
Mutual labels:  task, scheduler
Ppgo job
PPGo_Job是一款可视化的、多人多权限的、一任务多机执行的定时任务管理系统,采用golang开发,安装方便,资源消耗少,支持大并发,可同时管理多台服务器上的定时任务。
Stars: ✭ 1,152 (+3100%)
Mutual labels:  task, job-scheduler
Workq
Job server in Go
Stars: ✭ 1,546 (+4194.44%)
Mutual labels:  scheduler, job-scheduler
Cylc Flow
Cylc: a workflow engine for cycling systems. Repository master branch: core meta-scheduler component of cylc-8 (in development); Repository 7.8.x branch: full cylc-7 system.
Stars: ✭ 154 (+327.78%)
Mutual labels:  scheduler, job-scheduler
Ects
Elastic Crontab System 简单易用的分布式定时任务管理系统
Stars: ✭ 156 (+333.33%)
Mutual labels:  task, scheduler
croner
Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.
Stars: ✭ 169 (+369.44%)
Mutual labels:  task, scheduler

go-xxl-job-client

xxl-job go 客户端版

介绍

xxj-job 是一个 Java 实现的轻量级分布式任务调度平台,具体实现与使用请参考https://github.com/xuxueli/xxl-job,原版执行器亦要求 Java 平台,但公司部分项目是 golang 开发,所以自己实现了 go 版本的执行器。

写在前面

  • 我所实现的 go 客户端执行器 rpc 通信采用 dubbo-go 所用的类型 Java netty 的自研通信框架 getty(请参考:https://github.com/dubbogo/getty).
  • 整个设计实现是参考 xxl-job-core 的源码实现了 go 版本,核心在于 admin 与执行器的 rpc 通讯采用的序列化方式是 hessian2,所有借用了 apache 实现的 dubbo-go-hessian2(参考https://github.com/apache/dubbo-go-hessian2)。
  • 支持了 shell, python, php, js, powershell,暂不支持动态编译的 groovy 模式。
  • 脚本模式的分片参数会作为启动脚本时的最后两个参数,用户参数按顺序位于分片参数之前。

部署 xxl-job-admin

详细步骤请参考https://github.com/xuxueli/xxl-job, 此处不再描述 admin 的部署。

部署 xxl-job 执行器(go 版本)

(1) 引入 go 客户端依赖

go get github.com/feixiaobo/go-xxl-job-client/v2

(2) 在 main 方法中构建客户端 client,注册任务,启动端口

(1) 实现任务

func XxlJobTest(ctx context.Context) error {
	logger.Info(ctx, "golang job run success >>>>>>>>>>>>>>")
	logger.Info(ctx, "the input param:", xxl.GetParam(ctx, "name"))
	return nil
}

(2) 注册执行,任务,启动项目(可参考 example 目录)

	client := xxl.NewXxlClient(
	        option.WithAppName("go-example"),
                option.WithEnableHttp(true), //xxl_job v2.2.0版本及以后
		option.WithClientPort(8083),
	) //构建客户端
	client.RegisterJob("testJob", JobTest) //注册任务
	client.Run() //启动客户端
  • 构建客户端时的 appName 是 xxl-job-admin 后台添加执行器时的 name
  • 注册任务时的名字是 xxl-job-admin 后台新增任务时的 JobHandler

(3) 在 xxl-job-admin 后台管理页面添加执行器

  • appName 为客户注册执行器时的名字
  • 注册方式选择自动注册

(4) 在 xxl-job-admin 后台管理页面添加任务

  • JobHandler 为注册任务时的 name
  • 执行器选择刚刚添加的执行器
  • 运行模式默认 BEAN 模式,可选择其他脚本模式(不支持 GLUE(Java))

添加完成后启动在任务管理菜单中查看任务

日志输出及参数传递

  • go-xxl-job-client 自己实现了日志输出,使用 github.com/feixiaobo/go-xxl-job-client/v2/logger 包输出日志,因为 golang 不支持像 Java 的 ThreadLocal 一样的线程变量,已无法获取到 golang 的协程 id,所以日志输出依赖的内容已存到 context 上下文遍历中,故 log 需要使用 context 变量。可参考任务配置中的日志输出,
	logger.Info(ctx, "golang job run success >>>>>>>>>>>>>>")
  • 任务参数传递,可使用 xxl.GetParam 获取到任务配置或执行时手动添加的参数,使用 xxl.GetSharding 获取到分片参数。
        param, _ := xxl.GetParam(ctx, "name") //获取输入参数
        logger.Info(ctx, "the input param:", param)
        shardingIdx, shardingTotal := xxl.GetSharding(ctx) //获取分片参数
        logger.Info(ctx, "the sharding param: idx:", shardingIdx, ", total:", shardingTotal)

在调度日志中点击执行日志查看任务执行日志。

F&Q

(1) 遇到错误:register executor failed, please check xxl admin address or accessToken

xxl_job_admin地址不通或者accessToken错误,请检查是否配置了AdminAddress

(2) 执行任务admin端报错:java.net.MalformedURLException: no protocol: 192.168.0.105:8083/run

xxl_job_admin v2.2.0之后和客户端通信采用http/https通信。需在client端开启http协议,在client option中构造 option.WithEnableHttp(true), 参考 example下client_test。 旧版本请不要添加这个option
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].