From 1e6e64177197f33668e4dd65d7347cd283cb7dd7 Mon Sep 17 00:00:00 2001 From: yf <291323003@qq.com> Date: Fri, 15 Feb 2019 13:13:25 +0800 Subject: [PATCH] require swoole 4.2.13 --- src/Core.php | 26 +-------------- src/Swoole/PipeMessage/Message.php | 48 ---------------------------- src/Swoole/PipeMessage/OnCommand.php | 17 ---------- src/Swoole/Task/TaskManager.php | 30 +---------------- 4 files changed, 2 insertions(+), 119 deletions(-) delete mode 100644 src/Swoole/PipeMessage/Message.php delete mode 100644 src/Swoole/PipeMessage/OnCommand.php diff --git a/src/Core.php b/src/Core.php index 43aa657e..c5c61355 100644 --- a/src/Core.php +++ b/src/Core.php @@ -26,8 +26,6 @@ use EasySwoole\Trace\AbstractInterface\LoggerInterface; use EasySwoole\Trace\AbstractInterface\TriggerInterface; use EasySwoole\Trace\Bean\Location; -use EasySwoole\EasySwoole\Swoole\PipeMessage\Message; -use EasySwoole\EasySwoole\Swoole\PipeMessage\OnCommand; use EasySwoole\EasySwoole\Swoole\Task\AbstractAsyncTask; use EasySwoole\EasySwoole\Swoole\Task\SuperClosure; use Swoole\Server\Task; @@ -361,33 +359,11 @@ private function registerDefaultCallBack(\swoole_server $server,int $serverType) return null; }); } + EventHelper::on($server,EventRegister::onFinish,function (){ //空逻辑 }); - //通过pipe通讯,也就是processAsync投递的闭包任务,是没有taskId信息的,因此参数传递默认-1 - OnCommand::getInstance()->set('TASK',function (\swoole_server $server,$taskObj,$fromWorkerId){ - //闭包任务无法再次二次序列化,因此直接执行 - if($taskObj instanceof SuperClosure){ - try{ - call_user_func($taskObj,$server,-1,$fromWorkerId); - }catch (\Throwable $throwable){ - Trigger::getInstance()->throwable($throwable); - } - }else{ - $server->task($taskObj); - } - }); - - EventHelper::on($server,EventRegister::onPipeMessage,function (\swoole_server $server,$fromWorkerId,$data){ - $message = unserialize($data); - if($message instanceof Message){ - OnCommand::getInstance()->hook($message->getCommand(),$server,$message->getData(),$fromWorkerId); - }else{ - Trigger::getInstance()->error("data :{$data} not packet as an Message Instance"); - } - }); - //注册默认的worker start EventHelper::registerWithAdd(ServerManager::getInstance()->getMainEventRegister(),EventRegister::onWorkerStart,function (\swoole_server $server,$workerId){ if(PHP_OS != 'Darwin'){ diff --git a/src/Swoole/PipeMessage/Message.php b/src/Swoole/PipeMessage/Message.php deleted file mode 100644 index f43e1829..00000000 --- a/src/Swoole/PipeMessage/Message.php +++ /dev/null @@ -1,48 +0,0 @@ -command; - } - - /** - * @param mixed $command - */ - public function setCommand($command): void - { - $this->command = $command; - } - - /** - * @return mixed - */ - public function getData() - { - return $this->data; - } - - /** - * @param mixed $data - */ - public function setData($data): void - { - $this->data = $data; - } -} \ No newline at end of file diff --git a/src/Swoole/PipeMessage/OnCommand.php b/src/Swoole/PipeMessage/OnCommand.php deleted file mode 100644 index cdcfc49c..00000000 --- a/src/Swoole/PipeMessage/OnCommand.php +++ /dev/null @@ -1,17 +0,0 @@ -getSwooleServer()->setting; - $workerNum = $conf['worker_num']; - if(!isset($conf['task_worker_num'])){ - return false; - } - $taskNum = $conf['task_worker_num']; - $closure = false; - if($task instanceof \Closure){ - try{ - $task = new SuperClosure($task); - $closure = true; - }catch (\Throwable $throwable){ - Trigger::getInstance()->throwable($throwable); - return false; - } - } - $message = new Message(); - $message->setCommand('TASK'); - $message->setData($task); - mt_srand(); - //闭包无法再onPipeMessage中再次被序列化,因此直接投递给task进程直接执行。 - if($closure){ - $workerId = mt_rand($workerNum,($workerNum+$taskNum)-1); - }else{ - $workerId = mt_rand(0,$workerNum -1); - } - ServerManager::getInstance()->getSwooleServer()->sendMessage(serialize($message),$workerId); - return true; + return self::async($task); } public static function sync($task,$timeout = 0.5,$taskWorkerId = -1)