diff --git a/System/Crontab/Consumer.php b/System/Crontab/Consumer.php index e9fa19ff..390d1db5 100644 --- a/System/Crontab/Consumer.php +++ b/System/Crontab/Consumer.php @@ -41,12 +41,22 @@ class Consumer extends Process */ public function popChannel() { + /** @var Crontab $crontab */ $crontab = $this->channel->pop(-1); - go(function () use ($crontab) { - $this->dispatch($crontab); + try { + $crontab->increment()->execute(); + if ($crontab->getExecuteNumber() < $crontab->getMaxExecuteNumber()) { + Consumer::addTask($crontab); + } else if ($crontab->isLoop()) { + Consumer::addTask($crontab); + } + } catch (\Throwable $throwable) { + $this->application->addError($throwable->getMessage()); + } finally { + fire(Event::SYSTEM_RESOURCE_RELEASES); + } }); - $this->popChannel(); } @@ -76,28 +86,11 @@ class Consumer extends Process } - /** - * @param Crontab $value - * @throws Exception - */ - private function dispatch(Crontab $value) - { - $value->increment()->execute(); - if ($value->getExecuteNumber() < $value->getMaxExecuteNumber()) { - $this->addTask($value); - } else if ($value->isLoop()) { - $this->addTask($value); - } - var_dump($value); - fire(Event::SYSTEM_RESOURCE_RELEASES); - } - - /** * @param Crontab $crontab * @throws Exception */ - private function addTask(Crontab $crontab) + private static function addTask(Crontab $crontab) { $redis = Snowflake::app()->getRedis(); diff --git a/System/Crontab/Crontab.php b/System/Crontab/Crontab.php index ec2e9279..ea434235 100644 --- a/System/Crontab/Crontab.php +++ b/System/Crontab/Crontab.php @@ -181,10 +181,10 @@ class Crontab extends BaseObject } - /** - * - * @throws Exception - */ + /** + * + * @throws Exception + */ public function clearTimer() { $this->warning('crontab timer clear.'); @@ -199,14 +199,8 @@ class Crontab extends BaseObject */ public function execute(): void { - try { -// $result = call_user_func($this->handler, $this->params, $this->name); - var_dump(($this->handler)($this->params, $this->name)); - } catch (\Throwable $throwable) { - $this->addError($throwable->getMessage()); - } finally { - fire(Event::SYSTEM_RESOURCE_RELEASES); - } + var_dump(call_user_func($this->handler, $this->params, $this->name)); + }