{"id":33983981,"url":"https://github.com/thinkphp6/think-queue","last_synced_at":"2025-12-13T04:14:52.676Z","repository":{"id":57068863,"uuid":"390923730","full_name":"thinkphp6/think-queue","owner":"thinkphp6","description":"ThinkPHP6 队列","archived":false,"fork":false,"pushed_at":"2021-07-30T04:20:34.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-19T06:03:20.522Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thinkphp6.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-07-30T03:59:18.000Z","updated_at":"2024-04-19T06:03:20.523Z","dependencies_parsed_at":"2022-08-24T14:54:13.566Z","dependency_job_id":null,"html_url":"https://github.com/thinkphp6/think-queue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thinkphp6/think-queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp6%2Fthink-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp6%2Fthink-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp6%2Fthink-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp6%2Fthink-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkphp6","download_url":"https://codeload.github.com/thinkphp6/think-queue/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkphp6%2Fthink-queue/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27699702,"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","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-12-13T04:14:52.097Z","updated_at":"2025-12-13T04:14:52.670Z","avatar_url":"https://github.com/thinkphp6.png","language":"PHP","readme":"# think-queue for ThinkPHP6\n\n## 安装\n\n\u003e composer require thinkphp6/think-queue:dev-main\n\n## 配置\n\n\u003e 配置文件位于 `config/queue.php`\n\n### 公共配置\n\n```bash\n[\n    'default'=\u003e'sync' //驱动类型，可选择 sync(默认):同步执行，database:数据库驱动,redis:Redis驱动//或其他自定义的完整的类名\n]\n```\n\n\n## 创建任务类\n\u003e 单模块项目推荐使用 `app\\job` 作为任务类的命名空间\n\u003e 多模块项目可用使用 `app\\module\\job` 作为任务类的命名空间\n\u003e 也可以放在任意可以自动加载到的地方\n\n任务类不需继承任何类，如果这个类只有一个任务，那么就只需要提供一个`fire`方法就可以了，如果有多个小任务，就写多个方法，下面发布任务的时候会有区别  \n每个方法会传入两个参数 `think\\queue\\Job $job`（当前的任务对象） 和 `$data`（发布任务时自定义的数据）\n\n还有个可选的任务失败执行的方法 `failed` 传入的参数为`$data`（发布任务时自定义的数据）\n\n### 下面写两个例子\n\n```php\nnamespace app\\job;\n\nuse think\\queue\\Job;\n\nclass Job1{\n    \n    public function fire(Job $job, $data){\n    \n            //....这里执行具体的任务 \n            \n             if ($job-\u003eattempts() \u003e 3) {\n                  //通过这个方法可以检查这个任务已经重试了几次了\n             }\n            \n            \n            //如果任务执行成功后 记得删除任务，不然这个任务会重复执行，直到达到最大重试次数后失败后，执行failed方法\n            $job-\u003edelete();\n            \n            // 也可以重新发布这个任务\n            $job-\u003erelease($delay); //$delay为延迟时间\n          \n    }\n    \n    public function failed($data){\n    \n        // ...任务达到最大重试次数后，失败了\n    }\n\n}\n\n```\n\n```php\n\nnamespace app\\lib\\job;\n\nuse think\\queue\\Job;\n\nclass Job2{\n    \n    public function task1(Job $job, $data){\n    \n          \n    }\n    \n    public function task2(Job $job, $data){\n    \n          \n    }\n    \n    public function failed($data){\n    \n          \n    }\n\n}\n\n```\n\n\n## 发布任务\n\u003e `think\\facade\\Queue::push($job, $data = '', $queue = null)` 和 `think\\facade\\Queue::later($delay, $job, $data = '', $queue = null)` 两个方法，前者是立即执行，后者是在`$delay`秒后执行\n\n`$job` 是任务名  \n单模块的，且命名空间是`app\\job`的，比如上面的例子一,写`Job1`类名即可  \n多模块的，且命名空间是`app\\module\\job`的，写`model/Job1`即可  \n其他的需要些完整的类名，比如上面的例子二，需要写完整的类名`app\\lib\\job\\Job2`  \n如果一个任务类里有多个小任务的话，如上面的例子二，需要用@+方法名`app\\lib\\job\\Job2@task1`、`app\\lib\\job\\Job2@task2`\n\n`$data` 是你要传到任务里的参数\n\n`$queue` 队列名，指定这个任务是在哪个队列上执行，同下面监控队列的时候指定的队列名,可不填\n\n## 监听任务并执行\n\n```bash\n\u0026\u003e php think queue:listen\n\n\u0026\u003e php think queue:work\n```\n\n两种，具体的可选参数可以输入命令加 `--help` 查看\n\n\u003e 可配合supervisor使用，保证进程常驻\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkphp6%2Fthink-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkphp6%2Fthink-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkphp6%2Fthink-queue/lists"}