{"id":21688741,"url":"https://github.com/hyperf-glory/task-schedule","last_synced_at":"2025-04-12T09:22:11.143Z","repository":{"id":38252807,"uuid":"336762543","full_name":"Hyperf-Glory/Task-Schedule","owner":"Hyperf-Glory","description":"基于Hyperf开发的任务调度系统","archived":false,"fork":false,"pushed_at":"2021-05-17T02:28:36.000Z","size":1011,"stargazers_count":27,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-26T04:21:36.968Z","etag":null,"topics":["hyperf","nsq","redis","swoole","task"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/Hyperf-Glory.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}},"created_at":"2021-02-07T10:49:00.000Z","updated_at":"2024-05-11T06:13:40.000Z","dependencies_parsed_at":"2022-09-08T10:54:52.546Z","dependency_job_id":null,"html_url":"https://github.com/Hyperf-Glory/Task-Schedule","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyperf-Glory%2FTask-Schedule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyperf-Glory%2FTask-Schedule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyperf-Glory%2FTask-Schedule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hyperf-Glory%2FTask-Schedule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hyperf-Glory","download_url":"https://codeload.github.com/Hyperf-Glory/Task-Schedule/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248544122,"owners_count":21121898,"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":["hyperf","nsq","redis","swoole","task"],"created_at":"2024-11-25T17:16:26.929Z","updated_at":"2025-04-12T09:22:11.122Z","avatar_url":"https://github.com/Hyperf-Glory.png","language":"PHP","readme":"# Task-Schedule\n\n基于Hyperf开发的任务调度系统\n\n基于 Hyperf + Nsq 的一个异步队列库.支持投递任务，DAG任务编排.多个任务使用同一个事务。\n\n## 特性\n\n- 默认 Nsq 驱动\n- 秒级延时任务\n- 自定义重试次数和时间\n- 自定义错误回调\n- 支持任务执行中间件\n- 自定义队列快照事件\n- 弹性多进程消费\n- 协程支持\n- 漂亮的仪表盘\n- 任务编排协程安全的单连接模式(事务保持、多路复用等条件下，有时必须使用一个连接)\n- dag任务编排\n\n## 环境\n\n- PHP 7.4+\n- Swoole 4.6+\n- Redis 5.0+ (redis 驱动)\n- Nsq 1.2.0\n\n## TODO\n- RestApi支持投递,查看任务状态\n- web界面\n- 分布式支持\n- 接入报警\n\n## 案例\n\n1.投递任务\n\n```php\nuse App\\Model\\Task;\nuse App\\Job\\SimpleJob;\nuse App\\Kernel\\Nsq\\Queue;\nclass Example{\n     /**\n     * @desc 测试job队列功能\n     */\n    public function queue() : void\n    {\n        $task = Task::find(1);\n\n        $job = new SimpleJob($task);\n\n        $queue = new Queue('queue');\n        $queue-\u003epush($job);\n    }\n}\n```\n\n2.任务编排协程安全的单连接模式(事务保持、多路复用等条件下，有时必须使用一个连接)\n\n```php\nuse App\\Kernel\\Concurrent\\ConcurrentMySQLPattern;\nuse App\\Dag\\Task\\Task1;\nuse App\\Dag\\Task\\Task2;\nuse App\\Dag\\Task\\Task3;\nclass Example{\npublic function conCurrentMySQL() : void\n    {\n        $dsn      = 'DSN';\n        $user     = 'USER';\n        $password = 'PWD';\n        try {\n            $pdo = new \\PDO($dsn, $user, $password);\n            $pdo-\u003esetAttribute(\\PDO::ATTR_EMULATE_PREPARES, true);\n            $c = new ConcurrentMySQLPattern($pdo, $this-\u003elogger);\n            $c-\u003ebeginTransaction();\n            $dag     = new \\Hyperf\\Dag\\Dag();\n            $a       = \\Hyperf\\Dag\\Vertex::make(function () use ($c)\n            {\n                $task = new Task1();\n                return $task-\u003eRun($c);\n            }, 'a');\n            $b       = \\Hyperf\\Dag\\Vertex::make(function ($results) use ($c)\n            {\n                $task = new Task2();\n                return $task-\u003eRun($c);\n            }, 'b');\n            $d       = \\Hyperf\\Dag\\Vertex::make(function ($results) use ($c, $a, $b)\n            {\n                if ($results[$a-\u003ekey] \u0026\u0026 $results[$b-\u003ekey]) {\n                    return $c-\u003ecommit();\n                }\n                return $c-\u003erollback();\n            }, 'd');\n            $e       = \\Hyperf\\Dag\\Vertex::make(function ($results) use ($c)\n            {\n                $c-\u003eclose();\n            }, 'e');\n            $results = $dag\n                -\u003eaddVertex($a)\n                -\u003eaddVertex($b)\n                -\u003eaddVertex($d)\n                -\u003eaddVertex($e)\n                -\u003eaddEdge($a, $b)\n                -\u003eaddEdge($b, $d)\n                -\u003eaddEdge($d, $e)\n                -\u003erun();\n        } catch (\\PDOException $exception) {\n            echo 'Connection failed: ' . $exception-\u003egetMessage();\n        }\n    }\n}\n```\n\n3.仪表盘\n![img.png](img.png)\n\n4.TODO:\n![task-schedule.png](Task-Schedule.png)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperf-glory%2Ftask-schedule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperf-glory%2Ftask-schedule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperf-glory%2Ftask-schedule/lists"}