From 15421e665af64d91a04a5c81bf0e6d6d756afcf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 14 Apr 2021 11:41:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Crontab/Crontab.php | 25 +++++++++++++++++++++---- System/Crontab/CrontabProviders.php | 3 --- 2 files changed, 21 insertions(+), 7 deletions(-) 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)