https://github.com/cloud-org/crontab
Implement distributed task scheduling system with golang
https://github.com/cloud-org/crontab
crontab etcd golang mongodb
Last synced: about 1 year ago
JSON representation
Implement distributed task scheduling system with golang
- Host: GitHub
- URL: https://github.com/cloud-org/crontab
- Owner: cloud-org
- Created: 2019-10-18T16:12:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-31T14:10:48.000Z (almost 2 years ago)
- Last Synced: 2025-03-25T07:22:19.692Z (about 1 year ago)
- Topics: crontab, etcd, golang, mongodb
- Language: Go
- Homepage:
- Size: 2.79 MB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# crontab
golang 实现分布式任务调度系统
## 依赖
etcd、mongodb
### etcd
https://github.com/etcd-io/etcd
### mongodb
https://github.com/mongodb/mongo
## 架构
### master

### worker

#### 监听协程
利用 watch api,监听 /cron/jobs/ 和 /cron/killer/ 目录的变化
将变化时间通过 channel 推送给调度协程,更新内存中的任务信息
#### 调度协程
监听任务变更 event,更新内存中维护的任务列表
检查任务 cron 表达式,扫描到期任务,交给执行协程运行
监听任务控制 event,强制中断正在执行中的子进程
监听任务执行 result,更新内存中任务状态,投递执行日志
#### 执行协程
在 etcd 中抢占分布式乐观锁:/cron/lock/任务名
抢占成功则通过 Command 类执行 shell 任务
捕获 Command 输出并等待子进程结束,将执行结果投递给调度协程
备注:公平抢占依赖服务器时间同步
#### 日志协程
监听调度协程发来的执行日志,放入一个 batch 中
对新 batch 启动定时器,超时未满自动提交
若 batch 被放满,那么立即提交,并取消自动提交定时器
## 效果

## 致谢
https://yuerblog.cc
## TODO
- [ ] 任务超时控制
- [ ] 任务执行错误/超时进行告警