{"id":17355090,"url":"https://github.com/hezhizheng/go-crontab","last_synced_at":"2025-07-17T18:13:27.364Z","repository":{"id":55905082,"uuid":"314767789","full_name":"hezhizheng/go-crontab","owner":"hezhizheng","description":"windows 版 crontab | 基于 golang 的 crontab 定时任务管理器 （替代windows定时任务的一种方案）","archived":false,"fork":false,"pushed_at":"2024-12-02T12:53:03.000Z","size":77,"stargazers_count":49,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-10T05:42:11.886Z","etag":null,"topics":["crontab","go","go-crontab","golang","golang-crontab","windows","windows-crontab"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hezhizheng.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-21T08:34:31.000Z","updated_at":"2024-12-02T12:53:06.000Z","dependencies_parsed_at":"2024-11-15T12:04:39.023Z","dependency_job_id":"d46c69c2-9c15-46a2-8239-0b5bbc6001af","html_url":"https://github.com/hezhizheng/go-crontab","commit_stats":{"total_commits":21,"total_committers":2,"mean_commits":10.5,"dds":0.1428571428571429,"last_synced_commit":"852d82465339fbd88a6c2a481056ce36582f543e"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhizheng%2Fgo-crontab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhizheng%2Fgo-crontab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhizheng%2Fgo-crontab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhizheng%2Fgo-crontab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hezhizheng","download_url":"https://codeload.github.com/hezhizheng/go-crontab/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230479864,"owners_count":18232630,"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","go","go-crontab","golang","golang-crontab","windows","windows-crontab"],"created_at":"2024-10-15T17:42:14.824Z","updated_at":"2024-12-19T18:14:02.850Z","avatar_url":"https://github.com/hezhizheng.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Go-Crontab\n\n\u003e 基于 golang 的 crontab 定时任务管理器，解决在win环境开发下没有好用的定时任务管理器的囧境。\n\n### features\n- 支持分钟跟秒级\n- 自动识别当前系统 unix系统内部调用 `bash -c` 命令，windows 系统内部调用  `cmd /c`\n- 支持指定 bash 或 cmd 命令\n- 自动生成log日志文件记录  \n- 理论上跨平台支持 Windows 、Linux、MacOs\n- 自用test（windows下的确没啥好用的定时任务管理器。。。还不如自己搞一个）\n\n### 使用\n\n自定义json配置文件\n```\n# 参数说明\n{\n  # 支持定义多个定时任务，直接在 crontab_cmd 追加对象即可\n  \"app\": {\n    \"model\": \"s\", # 默认 s 秒级 如需使用分钟级改为 m\n    \"exec_mode\":\"bash\", # 默认空字符串,程序会根据当前操作系统自动区分执行bash还是cmd命令，支持指定命令执行，可选参数 bash/cmd\n    \"crontab_cmd\": [\n      {\n        \"crontab\": \"0/1 * * * * ?\", #crontab 表达式\n        \"cmd\": \"go version\" # 要执行的命令 \n      }\n    ]\n  }\n}\n\n# 支持实现 laravel 的任务调度 schedule:run (只支持分钟级别)，若想实现秒级驱动，指定 artisan 脚本名称即可\n# app.model 与 app.crontab_cmd.0.model (优先级最高) 都可以定义运行时间的驱动，可参考 Java(Quartz) 与 Linux Crontab 表达式书写\n# 或直接定义app.model 为 m ,则crontab表达式为 \"* * * * *\"\n# 命令表达式需要与对应环境匹配\n# 如 bash 环境下 的命令为：cd /e/www/project/dexter/laravel-test-demo \u0026\u0026 php artisan schedule:run \n# 那么 cmd 对应的命令就为：e: \u0026\u0026 cd E:\\www\\project\\dexter\\laravel-test-demo \u0026\u0026 php artisan schedule:run\n\n\n{\n  \"app\": {\n    \"model\": \"s\",\n    \"exec_mode\":\"bash\",\n    \"crontab_cmd\": [\n      {\n        \"crontab\": \"0/1 * * * * ?\",\n        \"cmd\": \"go version\",\n        \"model\": \"s\"\n      },\n      {\n        \"crontab\": \"* * * * *\",\n        \"cmd\": \"php -v\",\n        \"model\": \"m\"\n      }\n    ]\n  }\n}\n\n\n```\n\n### [执行路径名中存在空格的解决方案](https://github.com/hezhizheng/go-crontab/issues/2#issuecomment-932979020)\n\n### [可结合 winsw 将 go-crontab 打包成一个Windows服务在后台运行](https://github.com/hezhizheng/go-crontab/issues/4#issuecomment-1594526773)\n\n\n\n## 编译 \n(windows提供编译好的文件下载 [releases](https://github.com/hezhizheng/go-crontab/releases) )\n```\ngo build -ldflags \"-s -w\" -gcflags=\"all=-trimpath=${PWD}\" -asmflags=\"all=-trimpath=${PWD}\"\n```\n\n\n## 运行\n- 保证编译的文件与 config.json 在同级目录\n\n- 执行 ./go-crontab.exe (不要关闭终端)\n![free-pic](https://cdn.jsdelivr.net/gh/hezhizheng/static-image-hosting@main/image-hosting/20210518172138_ARNYYAIVNXHJPYKX.png)\n\n- 执行过程会自动生成log文件(保存一周，会定期清理)\n```log\n{\"level\":\"info\",\"msg\":\"执行命令： go version 输出： go version go1.15.2 windows/386\\n 执行耗时： 0.10 s\",\"time\":\"2021-07-24 10:39:00\"}\n{\"level\":\"info\",\"msg\":\"执行命令： php -f q.php 输出： sleep done 执行耗时： 5.15 s\",\"time\":\"2021-07-24 10:39:05\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhezhizheng%2Fgo-crontab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhezhizheng%2Fgo-crontab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhezhizheng%2Fgo-crontab/lists"}