mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-20 23:25:35 +08:00
add cron support (#232)
This commit is contained in:
@@ -7,10 +7,12 @@ namespace ZM\Annotation;
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Koriym\Attributes\AttributeReader;
|
||||
use Koriym\Attributes\DualReader;
|
||||
use ZM\Annotation\Framework\Cron;
|
||||
use ZM\Annotation\Http\Controller;
|
||||
use ZM\Annotation\Http\Route;
|
||||
use ZM\Annotation\Interfaces\ErgodicAnnotation;
|
||||
use ZM\Annotation\Middleware\Middleware;
|
||||
use ZM\Schedule\Schedule;
|
||||
use ZM\Store\FileSystem;
|
||||
use ZM\Utils\HttpUtil;
|
||||
|
||||
@@ -56,7 +58,8 @@ class AnnotationParser
|
||||
$this->special_parsers = [
|
||||
Middleware::class => [function (Middleware $middleware) { \middleware()->bindMiddleware([resolve($middleware->class), $middleware->method], $middleware->name, $middleware->params); }],
|
||||
Route::class => [[$this, 'addRouteAnnotation']],
|
||||
Closed::class => [function () { return false; }],
|
||||
Closed::class => [fn () => false],
|
||||
Cron::class => [[resolve(Schedule::class), 'addSchedule']],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
34
src/ZM/Annotation/Framework/Cron.php
Normal file
34
src/ZM/Annotation/Framework/Cron.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Framework;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @NamedArgumentConstructor()
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
|
||||
class Cron extends AnnotationBase
|
||||
{
|
||||
public CronExpression $expression;
|
||||
|
||||
/**
|
||||
* @param string $expression Cron 表达式
|
||||
* @param int $worker_id Worker ID
|
||||
* @param bool $no_overlap 是否不允许重叠执行
|
||||
*/
|
||||
public function __construct(
|
||||
string $expression,
|
||||
public int $worker_id = 0,
|
||||
public bool $no_overlap = false
|
||||
) {
|
||||
$this->expression = new CronExpression($expression);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user