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 Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use Swoole\Server;
use Swoole\Timer;
@@ -32,11 +33,15 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
public Router $router;
public EventDispatch $dispatch;
/**
* @return void
*/
public function init()
{
$this->dispatch = Kiri::getDi()->get(EventDispatch::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)
{
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnBeforeWorkerStart($workerId));
$this->dispatch->dispatch(new OnBeforeWorkerStart($workerId));
set_env('environmental_workerId', $workerId);
if ($workerId < $server->setting['worker_num']) {
set_env('environmental', Kiri::WORKER);
$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 {
set_env('environmental', Kiri::TASK);
$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 int $workerId
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws NotFoundExceptionInterface|ReflectionException
*/
public function onWorkerStop(Server $server, int $workerId)
{
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 int $workerId
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws NotFoundExceptionInterface|ReflectionException
*/
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)
{
\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',
$worker_id, $worker_pid, $signal, $exit_code, swoole_strerror(swoole_last_error(), 9)