浏览代码

tested crontab

mx 3 年之前
父节点
当前提交
88f2d06826
共有 4 个文件被更改,包括 86 次插入2 次删除
  1. 2 1
      composer.json
  2. 51 1
      composer.lock
  3. 3 0
      config/process.php
  4. 30 0
      process/Task.php

+ 2 - 1
composer.json

@@ -35,7 +35,8 @@
     "symfony/cache": "^5.4",
     "webman/console": "^1.0",
     "webman/redis-queue": "^1.1",
-    "symfony/translation": "^5.4"
+    "symfony/translation": "^5.4",
+    "workerman/crontab": "^1.0"
   },
   "suggest": {
     "ext-event": "For better performance. "

+ 51 - 1
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": "c162176b42a8c9d138c2a6bfa701ceb3",
+    "content-hash": "ba4d806e38ece83c2804652c3cb847a2",
     "packages": [
         {
             "name": "cakephp/core",
@@ -3080,6 +3080,56 @@
             },
             "time": "2022-03-25T08:58:10+00:00"
         },
+        {
+            "name": "workerman/crontab",
+            "version": "v1.0.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/walkor/crontab.git",
+                "reference": "28106241415049ee340a8a7cd9b640165240a2fa"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/walkor/crontab/zipball/28106241415049ee340a8a7cd9b640165240a2fa",
+                "reference": "28106241415049ee340a8a7cd9b640165240a2fa",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=7.0",
+                "workerman/workerman": ">=3.5.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Workerman\\Crontab\\": "./src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "walkor",
+                    "email": "walkor@workerman.net",
+                    "homepage": "http://www.workerman.net",
+                    "role": "Developer"
+                }
+            ],
+            "description": "A crontab written in PHP based on workerman",
+            "homepage": "http://www.workerman.net",
+            "keywords": [
+                "crontab"
+            ],
+            "support": {
+                "email": "walkor@workerman.net",
+                "forum": "http://wenda.workerman.net/",
+                "issues": "https://github.com/walkor/workerman/issues",
+                "source": "https://github.com/walkor/crontab",
+                "wiki": "http://doc.workerman.net/"
+            },
+            "time": "2021-10-06T14:18:14+00:00"
+        },
         {
             "name": "workerman/redis",
             "version": "v1.0.7",

+ 3 - 0
config/process.php

@@ -39,6 +39,9 @@ return [
         'listen' => 'websocket://0.0.0.0:8888',
         'count' => 1,
     ],
+    'task' => [
+        'handler' => process\Task::class,
+    ],
     // 'log_cleaner' => [
     //     'handler' => process\WorkerLogCleaner::class,
     // ]

+ 30 - 0
process/Task.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace process;
+
+use Workerman\Crontab\Crontab;
+
+class Task
+{
+	public function onWorkerStart()
+	{
+		// first second every minutes
+		new Crontab('1 * * * * *', function() {
+			echo '1st second of minutes';
+		});
+
+		// 7:50 of everyday
+		new Crontab('50 7 * * *', function() {
+
+		});
+
+		// every 2 minutes
+		new Crontab('*/2 * * * *', function() {
+			echo 'every 2 minutes';
+		});
+
+		new Crontab('*/5 * * * * *', function () {
+			echo 'every 5 seconds';
+		});
+	}
+}