{"id":15692587,"url":"https://github.com/liuyueyi/quick-task","last_synced_at":"2025-09-11T00:34:07.537Z","repository":{"id":52134164,"uuid":"142230498","full_name":"liuyueyi/quick-task","owner":"liuyueyi","description":"动态脚本调度框架，支持运行时新增，删除和修改动态脚本","archived":false,"fork":false,"pushed_at":"2023-12-05T22:20:21.000Z","size":37,"stargazers_count":7,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T04:34:17.337Z","etag":null,"topics":["commons-io","concurrent","groovy","java","quick"],"latest_commit_sha":null,"homepage":"https://blog.hhui.top/hexblog/categories/Quick%E7%B3%BB%E5%88%97/QuickTask/","language":"Java","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/liuyueyi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-25T01:21:56.000Z","updated_at":"2022-07-21T03:47:11.000Z","dependencies_parsed_at":"2024-10-24T00:14:16.779Z","dependency_job_id":"b4ff5e3c-9dd7-4b24-bf59-64447ad86e66","html_url":"https://github.com/liuyueyi/quick-task","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liuyueyi%2Fquick-task","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liuyueyi%2Fquick-task/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liuyueyi%2Fquick-task/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liuyueyi%2Fquick-task/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liuyueyi","download_url":"https://codeload.github.com/liuyueyi/quick-task/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252973622,"owners_count":21834105,"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":["commons-io","concurrent","groovy","java","quick"],"created_at":"2024-10-03T18:36:10.120Z","updated_at":"2025-05-07T23:47:31.649Z","avatar_url":"https://github.com/liuyueyi.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Quick-Task\n\n[![Builder](https://travis-ci.org/liuyueyi/quick-task.svg?branch=master)](https://travis-ci.org/liuyueyi/quick-task) \n[![](https://jitpack.io/v/liuyueyi/quick-task.svg)](https://jitpack.io/#liuyueyi/quick-task)\n\n一个简单的动态脚本调度框架，支持运行时，实时增加,删除和修改动态脚本，可用于后端的进行接口验证、数据订正，执行定时任务或校验脚本\n\n本项目主要涉及到的技术栈:\n\n- groovyEngine （groovy脚本加载执行）\n- commons-io （文件变动监听）\n- commons-cli (命令行参数解析)\n\n\n## I. 使用姿势\n\n### 1. pom配置\n\n两种使用姿势，一是我自己搭的私服，好处是更新及时；另一个是jitpack，优点是其对应的包就是github中的release版本\n\n**case1:**\n\n添加仓库地址\n\n```xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003eYiHui-Repo\u003c/id\u003e\n        \u003curl\u003ehttps://raw.githubusercontent.com/liuyueyi/maven-repository/master/repository\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\n添加项目依赖\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.git.hui\u003c/groupId\u003e\n    \u003cartifactId\u003etask-core\u003c/artifactId\u003e\n    \u003cversion\u003e0.0.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n**case2:**\n\n```xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003ejitpack.io\u003c/id\u003e\n        \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\n添加依赖\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.liuyueyi\u003c/groupId\u003e\n    \u003cartifactId\u003equick-task\u003c/artifactId\u003e\n    \u003cversion\u003ev0.0.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\n### 2. 使用demo\n\n#### a. 源码方式\n\n源码下载之后的使用case，可以参考 `com.git.hui.task.AppLaunch`，运行main方法，监听`./task-core/src/test/java/com/git/hui/task`目录下脚本的变动即可\n\n#### b. jar包引用\n\n首先准备一个Groovy脚本，放在指定的目录下，如 `/tmp/script/DemoScript.groovy`\n\n```groovy\npackage com.git.hui.task\n\nimport com.git.hui.task.api.ITask\n\nclass DemoScript implements ITask {\n    @Override\n    void run() {\n        println name() + \" | now \u003e : \u003e\u003e\" + System.currentTimeMillis()\n    }\n\n    @Override\n    void interrupt() {\n        println \"over\"\n    }\n}\n```\n\n对应的启动类可以如下\n\n```java\npublic class AppRunner {\n\n    // main 方式\n    public static void main(String[] args) throws Exception {\n        new ScriptExecuteEngine().run(\"/tmp/script/\");\n        Thread.sleep(24 *60 * 60 * 1000);\n    }\n    \n    // junit 方式启动\n    @Test\n    public void testTaskRun() {\n        new ScriptExecuteEngine().run(\"/tmp/script/\");\n        Thread.sleep(24 *60 * 60 * 1000);\n    }\n}\n```\n\n#### c. 测试\n\n应用启动完毕之后\n\n- 可以修改 `/tmp/script/DemoScript.groovy` 脚本的内容，保存后查看是否关闭旧的脚本并执行更新后的脚本\n- 测试在 `/tmp/script` 目录下新增脚本\n- 测试删除 `/tmp/script` 目录下的脚本\n- 测试异常的case (如非法的groovy文件，内部运行异常等...)\n\n**注意** 不要在groovy脚本中执行 `System.exit(1)`, 会导致整个项目都停止运行\n\n\n## II. 设计原理\n\n基本结构如下图\n\n![脚本框架.png](https://raw.githubusercontent.com/liuyueyi/Source/master/img/blog/daywork/180628/tech.png)\n\n从图中基本上也可以看出，这个项目的结构属于非常轻量级的，核心角色，有下面几个\n\n- Task ： 具体的任务脚本\n- TaskContainer： 持有执行任务的容器\n- TaskChangeWatcher： 任务观察器，用于查看是否有新增、删除or修改任务，从而卸载旧的任务，并加载新的任务\n\n\n另外一块属于扩展方面的插件体系，目前并没有给与实现，若将本框架继承在Spring生态体系中运行时，这些插件的支持就特别简单了\n\n- RedisTemplate\n- RestTemplate\n- AmqpTemplate\n- xxxTemplate\n\n## III. 其他\n\n### 0. 相关博文\n\n**涉及到技术点博文**\n\n- [180208-Java可以如何实现文件变动的监听](https://liuyueyi.github.io/hexblog/2018/02/08/Java%E5%8F%AF%E4%BB%A5%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E6%96%87%E4%BB%B6%E5%8F%98%E5%8A%A8%E7%9A%84%E7%9B%91%E5%90%AC/)\n- [180717-借助Maven打包可项目执行的Jar小记](https://liuyueyi.github.io/hexblog/2018/07/17/180717-%E5%80%9F%E5%8A%A9Maven%E6%89%93%E5%8C%85%E5%8F%AF%E9%A1%B9%E7%9B%AE%E6%89%A7%E8%A1%8C%E7%9A%84Jar%E5%B0%8F%E8%AE%B0/)\n- [180718-jar包执行传参使用小结](https://liuyueyi.github.io/hexblog/2018/07/18/180718-jar%E5%8C%85%E6%89%A7%E8%A1%8C%E4%BC%A0%E5%8F%82%E4%BD%BF%E7%94%A8%E5%B0%8F%E7%BB%93/)\n\n**框架相关博文**\n\n- [180628-动态任务执行框架想法篇](https://liuyueyi.github.io/hexblog/2018/06/28/180628-%E5%8A%A8%E6%80%81%E4%BB%BB%E5%8A%A1%E6%89%A7%E8%A1%8C%E6%A1%86%E6%9E%B6%E6%83%B3%E6%B3%95%E7%AF%87/)\n- [180702-QuickTask动态脚本支持框架整体介绍篇](https://liuyueyi.github.io/hexblog/2018/07/02/180702-QuickTask%E5%8A%A8%E6%80%81%E8%84%9A%E6%9C%AC%E6%94%AF%E6%8C%81%E6%A1%86%E6%9E%B6%E6%95%B4%E4%BD%93%E4%BB%8B%E7%BB%8D%E7%AF%87/)\n- [180719-Quick-Task 动态任务执行框架之使用介绍篇](https://liuyueyi.github.io/hexblog/2018/07/19/180719-Quick-Task-%E5%8A%A8%E6%80%81%E8%84%9A%E6%9C%AC%E6%94%AF%E6%8C%81%E6%A1%86%E6%9E%B6%E4%B9%8B%E4%BD%BF%E7%94%A8%E4%BB%8B%E7%BB%8D%E7%AF%87/)\n- [180723-Quick-Task 动态任务执行框架之结构设计篇](https://liuyueyi.github.io/hexblog/2018/07/23/180723-Quick-Task-%E5%8A%A8%E6%80%81%E8%84%9A%E6%9C%AC%E6%94%AF%E6%8C%81%E6%A1%86%E6%9E%B6%E4%B9%8B%E7%BB%93%E6%9E%84%E8%AE%BE%E8%AE%A1%E7%AF%87/)\n- [180729-Quick-Task 动态任务执行框架之任务动态加载](https://liuyueyi.github.io/hexblog/2018/07/29/180729-Quick-Task-%E5%8A%A8%E6%80%81%E8%84%9A%E6%9C%AC%E6%94%AF%E6%8C%81%E6%A1%86%E6%9E%B6%E4%B9%8B%E4%BB%BB%E5%8A%A1%E5%8A%A8%E6%80%81%E5%8A%A0%E8%BD%BD/)\n- [180807-Quick-Task 动态任务执行框架之Groovy脚本加载执行](https://liuyueyi.github.io/hexblog/2018/08/07/180807-Quick-Task-%E5%8A%A8%E6%80%81%E8%84%9A%E6%9C%AC%E6%94%AF%E6%8C%81%E6%A1%86%E6%9E%B6%E4%B9%8BGroovy%E8%84%9A%E6%9C%AC%E5%8A%A0%E8%BD%BD%E6%89%A7%E8%A1%8C/)\n\n\n### 1. [一灰灰Blog](https://liuyueyi.github.io/hexblog)： https://liuyueyi.github.io/hexblog\n\n一灰灰的个人博客，记录所有学习和工作中的博文，欢迎大家前去逛逛\n\n\n### 2. 声明\n\n尽信书则不如，已上内容，纯属一家之言，因个人能力有限，难免有疏漏和错误之处，如发现bug或者有更好的建议，欢迎批评指正，不吝感激\n\n- 微博地址: [小灰灰Blog](https://weibo.com/p/1005052169825577/home)\n- QQ： 一灰灰/3302797840\n- 微信: 一灰/liuyueyi25\n\n### 3. 扫描关注\n\n公众号\u0026博客\n\n![QrCode](https://gitee.com/liuyueyi/Source/raw/master/img/info/blogInfoV2.png)\n\n\n打赏码\n\n![pay](https://gitee.com/liuyueyi/Source/raw/master/img/pay/pay.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliuyueyi%2Fquick-task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliuyueyi%2Fquick-task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliuyueyi%2Fquick-task/lists"}