mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Added cron support for closure-command (#6495)
This commit is contained in:
parent
23ca774bee
commit
38e1d732a4
@ -8,6 +8,7 @@
|
||||
|
||||
- [#6483](https://github.com/hyperf/hyperf/pull/6483) [#6487] (https://github.com/hyperf/hyperf/pull/6487) Added new ways to register crontab.
|
||||
- [#6488](https://github.com/hyperf/hyperf/pull/6488) Added the default implement for `Psr\Log\LoggerInterface`.
|
||||
- [#6495](https://github.com/hyperf/hyperf/pull/6495) Added cron support for closure-command.
|
||||
|
||||
## Optimized
|
||||
|
||||
|
@ -12,8 +12,12 @@ declare(strict_types=1);
|
||||
namespace Hyperf\Command;
|
||||
|
||||
use Closure;
|
||||
use Hyperf\Crontab\Crontab;
|
||||
use Hyperf\Crontab\Schedule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
use function Hyperf\Tappable\tap;
|
||||
|
||||
final class ClosureCommand extends Command
|
||||
{
|
||||
private ParameterParser $parameterParser;
|
||||
@ -43,4 +47,20 @@ final class ClosureCommand extends Command
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(Crontab $crontab):Crontab|null $callback
|
||||
*/
|
||||
public function cron(string $rule, array $arguments = [], ?callable $callback = null): self
|
||||
{
|
||||
tap(
|
||||
Schedule::command($this->getName(), $arguments)
|
||||
->setName($this->getName())
|
||||
->setRule($rule)
|
||||
->setMemo($this->getDescription()),
|
||||
$callback
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user