Skip to content

Commit 72631c2

Browse files
authored
Added cron support for closure-command (#6495)
1 parent 9818c7c commit 72631c2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/ClosureCommand.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
namespace Hyperf\Command;
1313

1414
use Closure;
15+
use Hyperf\Crontab\Crontab;
16+
use Hyperf\Crontab\Schedule;
1517
use Psr\Container\ContainerInterface;
1618

19+
use function Hyperf\Tappable\tap;
20+
1721
final class ClosureCommand extends Command
1822
{
1923
private ParameterParser $parameterParser;
@@ -43,4 +47,20 @@ public function describe(string $description): self
4347

4448
return $this;
4549
}
50+
51+
/**
52+
* @param callable(Crontab $crontab):Crontab|null $callback
53+
*/
54+
public function cron(string $rule, array $arguments = [], ?callable $callback = null): self
55+
{
56+
tap(
57+
Schedule::command($this->getName(), $arguments)
58+
->setName($this->getName())
59+
->setRule($rule)
60+
->setMemo($this->getDescription()),
61+
$callback
62+
);
63+
64+
return $this;
65+
}
4666
}

0 commit comments

Comments
 (0)