mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 15:45:36 +08:00
add cron support (#232)
This commit is contained in:
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