add cron support (#232)

This commit is contained in:
sunxyw
2023-01-04 13:45:24 +08:00
committed by GitHub
parent 8f8002608e
commit 690f8aed10
4 changed files with 142 additions and 1 deletions

View 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);
}
}