{"id":26061959,"url":"https://github.com/cloud-org/crontab","last_synced_at":"2025-04-11T10:58:10.661Z","repository":{"id":42508316,"uuid":"216062446","full_name":"cloud-org/crontab","owner":"cloud-org","description":"Implement distributed task scheduling system with golang","archived":false,"fork":false,"pushed_at":"2024-07-31T14:10:48.000Z","size":2921,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T07:22:19.692Z","etag":null,"topics":["crontab","etcd","golang","mongodb"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloud-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-18T16:12:36.000Z","updated_at":"2024-07-31T14:10:53.000Z","dependencies_parsed_at":"2022-09-21T19:30:47.131Z","dependency_job_id":null,"html_url":"https://github.com/cloud-org/crontab","commit_stats":null,"previous_names":["ronething/golang-crontab"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-org%2Fcrontab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-org%2Fcrontab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-org%2Fcrontab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-org%2Fcrontab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloud-org","download_url":"https://codeload.github.com/cloud-org/crontab/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248381642,"owners_count":21094524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crontab","etcd","golang","mongodb"],"created_at":"2025-03-08T15:48:49.511Z","updated_at":"2025-04-11T10:58:10.635Z","avatar_url":"https://github.com/cloud-org.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crontab\n\ngolang 实现分布式任务调度系统\n\n## 依赖\n\netcd、mongodb\n\n### etcd\n\nhttps://github.com/etcd-io/etcd\n\n### mongodb\n\nhttps://github.com/mongodb/mongo\n\n## 架构\n\n### master\n\n![image](https://github.com/user-attachments/assets/9d247be7-0719-4ee4-8580-fde36405cd3f)\n\n### worker\n\n![image](https://github.com/user-attachments/assets/a0222337-c114-419c-87f8-380f45000c9e)\n\n#### 监听协程\n\n利用 watch api，监听 /cron/jobs/ 和 /cron/killer/ 目录的变化\n\n将变化时间通过 channel 推送给调度协程，更新内存中的任务信息\n\n#### 调度协程\n\n监听任务变更 event，更新内存中维护的任务列表\n\n检查任务 cron 表达式，扫描到期任务，交给执行协程运行\n\n监听任务控制 event，强制中断正在执行中的子进程\n\n监听任务执行 result，更新内存中任务状态，投递执行日志\n\n#### 执行协程\n\n在 etcd 中抢占分布式乐观锁：/cron/lock/任务名\n\n抢占成功则通过 Command 类执行 shell 任务\n\n捕获 Command 输出并等待子进程结束，将执行结果投递给调度协程\n\n备注：公平抢占依赖服务器时间同步\n\n#### 日志协程\n\n监听调度协程发来的执行日志，放入一个 batch 中\n\n对新 batch 启动定时器，超时未满自动提交\n\n若 batch 被放满，那么立即提交，并取消自动提交定时器\n\n## 效果\n\n![crontab](./images/crontab.png)\n\n## 致谢\n\nhttps://yuerblog.cc\n\n## TODO\n\n- [ ] 任务超时控制\n- [ ] 任务执行错误/超时进行告警\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud-org%2Fcrontab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloud-org%2Fcrontab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud-org%2Fcrontab/lists"}