Added cron support for closure-command (#6495)

This commit is contained in:
Deeka Wong 2024-01-24 14:16:09 +08:00 committed by GitHub
parent 23ca774bee
commit 38e1d732a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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;
}
}