rkljw 4 ماه پیش
والد
کامیت
516d9284b8

+ 36 - 0
app/Task/CollectorTask.php

@@ -0,0 +1,36 @@
+<?php
+namespace App\Task;
+
+use Hyperf\Contract\StdoutLoggerInterface;
+use Hyperf\Crontab\Annotation\Crontab;
+use Hyperf\Di\Annotation\Inject;
+use Hyperf\Coroutine\Exception\ParallelExecutionException;
+use Hyperf\Coroutine\Coroutine;
+use Hyperf\Coroutine\Parallel;
+
+#[Crontab(name: "Fooss", rule: "*/1 * * * *", callback: "", memo: "这是一个示例的定时任务")]
+class CollectorTask
+{
+
+    #[Crontab(rule: "*/1 * * * *", memo: "测试数据001")]
+    public function foo()
+    {
+        var_dump('试试');
+        $parallel = new Parallel(5);
+        for ($i = 0; $i < 20; $i++) {
+            $parallel->add(function () {
+                sleep(1);
+                return Coroutine::id();
+            });
+        }
+
+        try{
+            $results = $parallel->wait();
+            var_dump($results);
+        } catch(ParallelExecutionException $e){
+            // $e->getResults() 获取协程中的返回值。
+            // $e->getThrowables() 获取协程中出现的异常。
+        }
+
+    }
+}

+ 1 - 0
composer.json

@@ -19,6 +19,7 @@
         "hyperf/config": "~3.1.0",
         "hyperf/config-nacos": "^3.1",
         "hyperf/constants": "^3.1",
+        "hyperf/crontab": "^3.1",
         "hyperf/database": "~3.1.0",
         "hyperf/db-connection": "~3.1.0",
         "hyperf/di": "^3.1",

+ 74 - 3
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "1935bfafe4523350f25d98a64e75d710",
+    "content-hash": "9464531324876b68f8d73156c7d11cf3",
     "packages": [
         {
             "name": "carbonphp/carbon-doctrine-types",
@@ -1818,6 +1818,77 @@
             ],
             "time": "2024-09-25T02:54:12+00:00"
         },
+        {
+            "name": "hyperf/crontab",
+            "version": "v3.1.42",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/hyperf/crontab.git",
+                "reference": "be1187515aabbfe96b2f6a5330b4ddd742e971c7"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/hyperf/crontab/zipball/be1187515aabbfe96b2f6a5330b4ddd742e971c7",
+                "reference": "be1187515aabbfe96b2f6a5330b4ddd742e971c7",
+                "shasum": ""
+            },
+            "require": {
+                "hyperf/conditionable": "~3.1.0",
+                "hyperf/framework": "~3.1.0",
+                "hyperf/support": "~3.1.0",
+                "hyperf/tappable": "~3.1.0",
+                "hyperf/utils": "~3.1.0",
+                "nesbot/carbon": "^2.0",
+                "php": ">=8.1"
+            },
+            "suggest": {
+                "hyperf/command": "Required to use command trigger.",
+                "hyperf/process": "Auto register the Crontab process for server."
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "3.1-dev"
+                },
+                "hyperf": {
+                    "config": "Hyperf\\Crontab\\ConfigProvider"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Hyperf\\Crontab\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "description": "A crontab component for Hyperf.",
+            "homepage": "https://hyperf.io",
+            "keywords": [
+                "crontab",
+                "hyperf",
+                "php",
+                "swoole"
+            ],
+            "support": {
+                "docs": "https://hyperf.wiki",
+                "issues": "https://github.com/hyperf/hyperf/issues",
+                "pull-request": "https://github.com/hyperf/hyperf/pulls",
+                "source": "https://github.com/hyperf/hyperf"
+            },
+            "funding": [
+                {
+                    "url": "https://hyperf.wiki/#/zh-cn/donate",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://opencollective.com/hyperf",
+                    "type": "open_collective"
+                }
+            ],
+            "time": "2024-09-25T02:54:12+00:00"
+        },
         {
             "name": "hyperf/database",
             "version": "v3.1.44",
@@ -10272,12 +10343,12 @@
     ],
     "aliases": [],
     "minimum-stability": "dev",
-    "stability-flags": {},
+    "stability-flags": [],
     "prefer-stable": true,
     "prefer-lowest": false,
     "platform": {
         "php": ">=8.1"
     },
-    "platform-dev": {},
+    "platform-dev": [],
     "plugin-api-version": "2.6.0"
 }

+ 6 - 0
config/autoload/crontab.php

@@ -0,0 +1,6 @@
+<?php
+// config/autoload/crontab.php
+use Hyperf\Crontab\Crontab;
+return [
+    'enable' => true,
+];

+ 1 - 0
config/autoload/processes.php

@@ -10,4 +10,5 @@ declare(strict_types=1);
  * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
  */
 return [
+    Hyperf\Crontab\Process\CrontabDispatcherProcess::class,
 ];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
runtime/container/classes.cache


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
runtime/container/scan.cache


+ 1 - 1
runtime/hyperf.pid

@@ -1 +1 @@
-249
+43059

+ 0 - 22
runtime/logs/hyperf.log

@@ -1,22 +0,0 @@
-[2024-11-11T07:09:14.025620+00:00] sql.INFO: [141.22] select * from `article` [] []
-[2024-11-11T07:10:46.911661+00:00] sql.INFO: [148.07] select * from `article` limit 1 [] []
-[2024-11-11T07:10:47.007749+00:00] sql.INFO: [70.84] select * from `col_article` limit 1 [] []
-[2024-11-11T07:24:22.378221+00:00] sql.INFO: [85.85] select * from `col_web` where (`name` = '中华人民共和国公安部') limit 1 [] []
-[2024-11-11T07:24:22.660190+00:00] sql.INFO: [267.67] insert into `col_web` (`name`, `url`) values ('中华人民共和国公安部', 'https://www.mps.gov.cn/') [] []
-[2024-11-11T07:24:26.380734+00:00] sql.INFO: [15.95] select * from `col_web` where (`name` = '中华人民共和国公安部') limit 1 [] []
-[2024-11-11T07:26:54.043337+00:00] sql.INFO: [82.76] select * from `col_web` where (`name` = '中华人民共和国公安部') limit 1 [] []
-[2024-11-11T07:27:49.603806+00:00] sql.INFO: [19.4] select * from `col_web` where (`name` = '中华人民共和国公安部') limit 1 [] []
-[2024-11-11T07:27:55.025670+00:00] sql.INFO: [167.04] select * from `col_web` where (`name` = '中华人民共和国公安部') limit 1 [] []
-[2024-11-11T07:27:55.249209+00:00] sql.INFO: [208.33] insert into `col_web` (`name`, `url`, `created_at`) values ('中华人民共和国公安部', 'https://www.mps.gov.cn/', '2024-11-11 15:27:55') [] []
-[2024-11-11T08:12:42.450348+00:00] sql.INFO: [116.62] select * from `col_web` [] []
-[2024-11-11T08:13:15.416245+00:00] sql.INFO: [17.45] select * from `col_web` where (`name` like '%公安部%') limit 1 [] []
-[2024-11-11T08:59:35.435894+00:00] sql.INFO: [119.84] select * from `col_web` where `id` = '1' limit 1 [] []
-[2024-11-11T08:59:35.832899+00:00] sql.INFO: [137.67] update `col_web` set `name` = '中华人民共和国', `url` = 'https://www.mps.gov.cn/', `id` = '1', `col_web`.`updated_at` = '2024-11-11 08:59:35' where `id` = '1' [] []
-[2024-11-11T08:59:41.213697+00:00] sql.INFO: [15.65] select * from `col_web` where (`name` like '%公安部%') limit 1 [] []
-[2024-11-11T09:00:56.091043+00:00] sql.INFO: [99.38] select * from `col_web` [] []
-[2024-11-11T09:01:30.424778+00:00] sql.INFO: [147.7] select * from `col_web` where (`name` = '中华人民共和国公安部') limit 1 [] []
-[2024-11-11T09:01:30.529718+00:00] sql.INFO: [89.83] insert into `col_web` (`name`, `url`, `created_at`) values ('中华人民共和国公安部', 'https://www.mps.gov.cn/', '2024-11-11 17:01:30') [] []
-[2024-11-11T09:01:34.547675+00:00] sql.INFO: [16.85] select * from `col_web` [] []
-[2024-11-11T09:01:38.495948+00:00] sql.INFO: [17.79] select * from `col_web` [] []
-[2024-11-11T09:01:57.723834+00:00] sql.INFO: [17.1] select * from `col_web` [] []
-[2024-11-11T09:02:04.206648+00:00] sql.INFO: [82.9] select * from `col_web` [] []

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است