modify plugin name

This commit is contained in:
2022-06-08 14:53:13 +08:00
parent 9db7143ed6
commit 0faa8f3ec4
+14 -10
View File
@@ -17,6 +17,7 @@ use Kiri\Server\Events\OnWorkerStart;
use Kiri\Server\Events\OnWorkerStop; use Kiri\Server\Events\OnWorkerStop;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use Swoole\Server; use Swoole\Server;
use Swoole\Timer; use Swoole\Timer;
@@ -32,11 +33,15 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
public Router $router; public Router $router;
public EventDispatch $dispatch;
/** /**
* @return void * @return void
*/ */
public function init() public function init()
{ {
$this->dispatch = Kiri::getDi()->get(EventDispatch::class);
$this->router = Kiri::getDi()->get(Router::class); $this->router = Kiri::getDi()->get(Router::class);
} }
@@ -52,19 +57,18 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
*/ */
public function onWorkerStart(Server $server, int $workerId) public function onWorkerStart(Server $server, int $workerId)
{ {
$dispatch = \Kiri::getDi()->get(EventDispatch::class); $this->dispatch->dispatch(new OnBeforeWorkerStart($workerId));
$dispatch->dispatch(new OnBeforeWorkerStart($workerId));
set_env('environmental_workerId', $workerId); set_env('environmental_workerId', $workerId);
if ($workerId < $server->setting['worker_num']) { if ($workerId < $server->setting['worker_num']) {
set_env('environmental', Kiri::WORKER); set_env('environmental', Kiri::WORKER);
$this->setProcessName(sprintf('Worker Process[%d].%d', $server->worker_pid, $workerId)); $this->setProcessName(sprintf('Worker Process[%d].%d', $server->worker_pid, $workerId));
$dispatch->dispatch(new OnWorkerStart($server, $workerId)); $this->dispatch->dispatch(new OnWorkerStart($server, $workerId));
} else { } else {
set_env('environmental', Kiri::TASK); set_env('environmental', Kiri::TASK);
$this->setProcessName(sprintf('Tasker Process[%d].%d', $server->worker_pid, $workerId)); $this->setProcessName(sprintf('Tasker Process[%d].%d', $server->worker_pid, $workerId));
$dispatch->dispatch(new OnTaskStart($server, $workerId)); $this->dispatch->dispatch(new OnTaskStart($server, $workerId));
} }
$dispatch->dispatch(new OnAfterWorkerStart()); $this->dispatch->dispatch(new OnAfterWorkerStart());
} }
@@ -72,12 +76,12 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
* @param Server $server * @param Server $server
* @param int $workerId * @param int $workerId
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface|ReflectionException
*/ */
public function onWorkerStop(Server $server, int $workerId) public function onWorkerStop(Server $server, int $workerId)
{ {
Timer::clearAll(); Timer::clearAll();
\Kiri::getDi()->get(EventDispatch::class)->dispatch(new OnWorkerStop($server, $workerId)); $this->dispatch->dispatch(new OnWorkerStop($server, $workerId));
} }
@@ -85,11 +89,11 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
* @param Server $server * @param Server $server
* @param int $workerId * @param int $workerId
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface|ReflectionException
*/ */
public function onWorkerExit(Server $server, int $workerId) public function onWorkerExit(Server $server, int $workerId)
{ {
\Kiri::getDi()->get(EventDispatch::class)->dispatch(new OnWorkerExit($server, $workerId)); $this->dispatch->dispatch(new OnWorkerExit($server, $workerId));
} }
@@ -105,7 +109,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
*/ */
public function onWorkerError(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal) public function onWorkerError(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal)
{ {
\Kiri::getDi()->get(EventDispatch::class)->dispatch(new OnWorkerError($server, $worker_id, $worker_pid, $exit_code, $signal)); $this->dispatch->dispatch(new OnWorkerError($server, $worker_id, $worker_pid, $exit_code, $signal));
$message = sprintf('Worker#%d::%d error stop. signal %d, exit_code %d, msg %s', $message = sprintf('Worker#%d::%d error stop. signal %d, exit_code %d, msg %s',
$worker_id, $worker_pid, $signal, $exit_code, swoole_strerror(swoole_last_error(), 9) $worker_id, $worker_pid, $signal, $exit_code, swoole_strerror(swoole_last_error(), 9)