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(); - } - } - - }