diff --git a/System/Crontab/Crontab.php b/System/Crontab/Crontab.php index a129afb1..0f9c24e9 100644 --- a/System/Crontab/Crontab.php +++ b/System/Crontab/Crontab.php @@ -42,6 +42,7 @@ class Crontab extends BaseObject private int $execute_number = 0; + private array|Closure|null $_max_execute_handler = null; /** @@ -197,7 +198,7 @@ class Crontab extends BaseObject /** - * @throws \Exception + * @throws Exception */ private function recover() { @@ -211,6 +212,15 @@ class Crontab extends BaseObject } + /** + * @param Closure|array $closure + */ + public function setMaxExecute(Closure|array $closure) + { + $this->_max_execute_handler = $closure; + } + + /** * @throws Exception */ @@ -241,14 +251,21 @@ class Crontab extends BaseObject /** - * @throws \Exception + * @throws Exception */ private function after(): void { + if ($this->isLoop()) { + $this->recover(); + return; + } + if ($this->max_execute_number == -1) { + return; + } if ($this->getExecuteNumber() < $this->getMaxExecuteNumber()) { $this->recover(); - } else if ($this->isLoop()) { - $this->recover(); + } else { + call_user_func($this->_max_execute_handler, ...$this->params); } } diff --git a/System/Crontab/CrontabProviders.php b/System/Crontab/CrontabProviders.php index 616d590e..d6bd3e6c 100644 --- a/System/Crontab/CrontabProviders.php +++ b/System/Crontab/CrontabProviders.php @@ -24,10 +24,7 @@ class CrontabProviders extends Providers /** * @param Application $application - * @throws ReflectionException - * @throws ComponentException * @throws ConfigException - * @throws NotFindClassException * @throws Exception */ public function onImport(Application $application)