modify plugin name

This commit is contained in:
2022-07-11 16:09:57 +08:00
parent 9a0294eaa2
commit 4ebd409853
3 changed files with 56 additions and 1 deletions
+12
View File
@@ -0,0 +1,12 @@
<?php
namespace Kiri\Server\Abstracts;
enum StatusEnum
{
case START;
case STOP;
case EXIT;
case ERROR;
}
+11 -1
View File
@@ -19,7 +19,10 @@ use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use ReflectionException; use ReflectionException;
use Swoole\Server; use Swoole\Server;
use Kiri\Server\Abstracts\StatusEnum;
use Kiri\Server\WorkerStatus;
use Swoole\Timer; use Swoole\Timer;
use Kiri\Annotation\Inject;
/** /**
@@ -32,10 +35,11 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
/** /**
* @param EventDispatch $dispatch * @param EventDispatch $dispatch
* @param WorkerStatus $status
* @param Router $router * @param Router $router
* @throws Exception * @throws Exception
*/ */
public function __construct(public EventDispatch $dispatch, public Router $router) public function __construct(public EventDispatch $dispatch, public WorkerStatus $status, public Router $router)
{ {
parent::__construct(); parent::__construct();
} }
@@ -53,6 +57,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
{ {
$this->dispatch->dispatch(new OnBeforeWorkerStart($workerId)); $this->dispatch->dispatch(new OnBeforeWorkerStart($workerId));
set_env('environmental_workerId', $workerId); set_env('environmental_workerId', $workerId);
$this->status->setEnum(StatusEnum::START);
if ($workerId < $server->setting['worker_num']) { if ($workerId < $server->setting['worker_num']) {
$this->dispatch->dispatch(new OnWorkerStart($server, $workerId)); $this->dispatch->dispatch(new OnWorkerStart($server, $workerId));
} else { } else {
@@ -70,6 +75,8 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
*/ */
public function onWorkerStop(Server $server, int $workerId) public function onWorkerStop(Server $server, int $workerId)
{ {
$this->status->setEnum(StatusEnum::STOP);
$this->dispatch->dispatch(new OnWorkerStop($server, $workerId)); $this->dispatch->dispatch(new OnWorkerStop($server, $workerId));
} }
@@ -82,6 +89,8 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
*/ */
public function onWorkerExit(Server $server, int $workerId) public function onWorkerExit(Server $server, int $workerId)
{ {
$this->status->setEnum(StatusEnum::EXIT);
$this->dispatch->dispatch(new OnWorkerExit($server, $workerId)); $this->dispatch->dispatch(new OnWorkerExit($server, $workerId));
} }
@@ -98,6 +107,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)
{ {
$this->status->setEnum(StatusEnum::ERROR);
$this->dispatch->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',
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace Kiri\Server;
use Kiri\Server\Abstracts\StatusEnum;
class WorkerStatus
{
public StatusEnum $enum;
/**
* @param StatusEnum $enum
*/
public function setEnum(StatusEnum $enum): void
{
$this->enum = $enum;
}
/**
* @param StatusEnum $enum
* @return bool
*/
public function is(StatusEnum $enum): bool
{
return $this->enum == $enum;
}
}