Skip to content

Commit

Permalink
require swoole 4.2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Feb 15, 2019
1 parent edbea2a commit 1e6e641
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 119 deletions.
26 changes: 1 addition & 25 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'){
Expand Down
48 changes: 0 additions & 48 deletions src/Swoole/PipeMessage/Message.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Swoole/PipeMessage/OnCommand.php

This file was deleted.

30 changes: 1 addition & 29 deletions src/Swoole/Task/TaskManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


use EasySwoole\EasySwoole\ServerManager;
use EasySwoole\EasySwoole\Swoole\PipeMessage\Message;
use EasySwoole\EasySwoole\Trigger;

class TaskManager
Expand All @@ -30,34 +29,7 @@ public static function async($task,$finishCallback = null,$taskWorkerId = -1)

public static function processAsync($task)
{
$conf = ServerManager::getInstance()->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)
Expand Down

0 comments on commit 1e6e641

Please sign in to comment.