一个分布式任务调度框架:调度中心集中管理任务,执行器通过注解接入业务代码,支持分片、失败转移、多语言接入、日志追踪与可视化运维。
- 集中式调度中心:Web UI 管理任务、执行器、调度日志
- 注解式接入:
@TaskPilot将任一 Spring Bean 方法注册为可调度任务 - 运行模式:Bean / GLUE (Groovy) / Shell / Python / PHP 等
- 路由策略:第一个、最后一个、轮询、随机、一致性 Hash、最不经常使用、最近最少使用、故障转移、忙碌转移、分片广播
- 分片广播 + 动态参数:海量数据并行处理
- 弹性容错:调度超时、失败告警、失败重试
- 日志回溯:任务执行日志按任务 ID 聚合,支持 rolling 自动清理
# 1. 本地构建各模块(开发态默认不会触发 release profile)
mvn -DskipTests clean install
# 2. 启动 Postgres + 调度中心 + 示例执行器
docker-compose up --build- 调度中心:http://127.0.0.1:8080 (默认账号
admin/123456) - 示例执行器:
http://127.0.0.1:9999 - PostgreSQL:
127.0.0.1:5432,库task_pilot
- 创建数据库:
psql -U postgres -c "CREATE DATABASE task_pilot;" - 启动
task-pilot-admin的TaskPilotAdminApplication - 启动
task-pilot-executor-sample-springboot的TaskPilotExecutorApplication
引入 Starter:
<dependency>
<groupId>com.ruishanio</groupId>
<artifactId>task-pilot-spring-boot-starter</artifactId>
<version>1.0.4</version>
</dependency>在任意 Spring Bean 中声明任务方法:
@Component
class SampleTask {
@TaskPilot("demoTaskHandler")
fun demoTaskHandler() {
TaskPilotHelper.log("hello task-pilot")
}
// 带自动注册,首次启动即在调度中心登记
@TaskPilotRegister(taskDesc = "分片任务", conf = "0/3 * * * * ?")
@TaskPilot("shardingTaskHandler")
fun shardingTaskHandler() {
val idx = TaskPilotHelper.getShardIndex()
val total = TaskPilotHelper.getShardTotal()
TaskPilotHelper.log("shard {}/{}", idx, total)
}
}更多示例见 task-pilot-executor-sample-springboot。
application.yml:
task-pilot:
admin:
addresses: http://127.0.0.1:8080
accessToken: default_token
timeout: 3
executor:
enabled: true
appname: task-pilot-executor-sample
ip: "" # 留空自动识别
port: 9999
logpath: ${user.home}/logs/task-pilot/taskhandler
logretentiondays: 30
sync:
enabled: true本项目采用 GPL-3.0 协议。