This commit is contained in:
2021-08-13 14:37:46 +08:00
parent de4e63d7f9
commit 15851ba97c
2 changed files with 35 additions and 23 deletions
+3 -2
View File
@@ -379,10 +379,11 @@ class ServerManager
/** /**
* @param TaskExecute|string $handler * @param TaskExecute|string $handler
* @param array $params * @param array $params
* @param int $workerId * @param int|null $workerId
* @throws ReflectionException
* @throws Exception * @throws Exception
*/ */
public function task(TaskExecute|string $handler, array $params = [], int $workerId = 0) public function task(TaskExecute|string $handler, array $params = [], int $workerId = null)
{ {
if ($workerId === null || $workerId <= $this->server->setting['worker_num']) { if ($workerId === null || $workerId <= $this->server->setting['worker_num']) {
$workerId = random_int($this->server->setting['worker_num'] + 1, $workerId = random_int($this->server->setting['worker_num'] + 1,
+15 -4
View File
@@ -22,10 +22,6 @@ use HttpServer\Server;
use HttpServer\Shutdown; use HttpServer\Shutdown;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kafka\KafkaProvider; use Kafka\KafkaProvider;
use ReflectionException;
use Rpc\Producer;
use Rpc\Service;
use Server\ServerManager;
use Kiri\Aop; use Kiri\Aop;
use Kiri\Async; use Kiri\Async;
use Kiri\Cache\Redis; use Kiri\Cache\Redis;
@@ -37,6 +33,11 @@ use Kiri\Exception\InitException;
use Kiri\Exception\NotFindClassException; use Kiri\Exception\NotFindClassException;
use Kiri\Jwt\Jwt; use Kiri\Jwt\Jwt;
use Kiri\Kiri; use Kiri\Kiri;
use ReflectionException;
use Rpc\Producer;
use Rpc\Service;
use Server\ServerManager;
use Server\SInterface\TaskExecute;
use Swoole\Table; use Swoole\Table;
/** /**
@@ -199,6 +200,16 @@ abstract class BaseApplication extends Component
} }
/**
* @param TaskExecute $execute
* @throws ReflectionException
*/
public function task(TaskExecute $execute): void
{
ServerManager::getContext()->task($execute);
}
/** /**
* @param $key * @param $key
* @param $value * @param $value