File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1212namespace Hyperf \Command ;
1313
1414use Closure ;
15+ use Hyperf \Crontab \Crontab ;
16+ use Hyperf \Crontab \Schedule ;
1517use Psr \Container \ContainerInterface ;
1618
19+ use function Hyperf \Tappable \tap ;
20+
1721final 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}
You can’t perform that action at this time.
0 commit comments