From e9243de9c11c6c88dac9df8a5c3f20e25c3e6198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 15 Apr 2021 21:16:48 +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 | 51 ++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/System/Crontab/Crontab.php b/System/Crontab/Crontab.php index 5c26ccc2..e4cfb719 100644 --- a/System/Crontab/Crontab.php +++ b/System/Crontab/Crontab.php @@ -207,6 +207,39 @@ abstract class Crontab extends BaseObject * @throws Exception */ public function execute(): void + { + \Swoole\Coroutine\go(function ($application) { + $application->isRecover($application); + }, $this); + $this->run(); + } + + + /** + * @param $application + * @throws Exception + */ + public function isRecover($application) + { + try { + if ($application->isExit()) { + return; + } + if ($application->isMaxExecute()) { + call_user_func([$application, 'max_execute'], ...$application->params); + } else { + $application->recover(); + } + } catch (\Throwable $throwable) { + logger()->addError($throwable, 'throwable'); + } + } + + + /** + * @throws Exception + */ + private function run() { try { $redis = Snowflake::app()->getRedis(); @@ -227,8 +260,6 @@ abstract class Crontab extends BaseObject ])); } catch (\Throwable $throwable) { logger()->addError($throwable, 'throwable'); - } finally { - $this->after(); } } @@ -260,20 +291,4 @@ abstract class Crontab extends BaseObject } - /** - * @throws Exception - */ - private function after(): void - { - if ($this->isExit()) { - return; - } - if ($this->isMaxExecute()) { - call_user_func([$this, 'max_execute'], ...$this->params); - } else { - $this->recover(); - } - } - - }