This commit is contained in:
2023-04-21 22:26:43 +08:00
parent ada0f49a43
commit f313860436
12 changed files with 25 additions and 135 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ class OnPipeMessage extends Server
* @param mixed $message
* @throws Exception
*/
public function onPipeMessage(\Swoole\Server $server, int $src_worker_id, mixed $message)
public function onPipeMessage(\Swoole\Server $server, int $src_worker_id, mixed $message): void
{
if (is_string($message)) {
$message = unserialize($message);
+6 -39
View File
@@ -32,12 +32,11 @@ class OnServer extends Server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function onStart(SServer $server)
public function onStart(SServer $server): void
{
\Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid));
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnStart($server));
event(new OnStart($server));
}
@@ -47,52 +46,20 @@ class OnServer extends Server
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function onBeforeShutdown(SServer $server)
public function onBeforeShutdown(SServer $server): void
{
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnBeforeShutdown($server));
event(new OnBeforeShutdown($server));
}
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
* @throws
*/
public function onShutdown(SServer $server): void
{
@unlink(storage('.swoole.pid'));
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnShutdown($server));
event(new OnShutdown($server));
}
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function onBeforeReload(SServer $server)
{
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnBeforeReload($server));
}
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function onAfterReload(SServer $server)
{
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnAfterReload($server));
}
}
+3 -6
View File
@@ -24,16 +24,14 @@ class OnServerManager extends Server
/**
* @param \Swoole\Server $server
* @throws ConfigException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|ReflectionException
*/
public function onManagerStart(\Swoole\Server $server)
public function onManagerStart(\Swoole\Server $server): void
{
Kiri::setProcessName(sprintf('manger process[%d]', $server->manager_pid));
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnManagerStart($server));
event(new OnManagerStart($server));
}
@@ -45,8 +43,7 @@ class OnServerManager extends Server
*/
public function onManagerStop(\Swoole\Server $server): void
{
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnManagerStop($server));
event(new OnManagerStop($server));
}
+7 -9
View File
@@ -58,10 +58,9 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|ReflectionException
*/
public function onWorkerStop(Server $server, int $workerId)
public function onWorkerStop(Server $server, int $workerId): void
{
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnWorkerStop($server, $workerId));
event(new OnWorkerStop($server, $workerId));
}
@@ -71,10 +70,9 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|ReflectionException
*/
public function onWorkerExit(Server $server, int $workerId)
public function onWorkerExit(Server $server, int $workerId): void
{
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnWorkerExit($server, $workerId));
event(new OnWorkerExit($server, $workerId));
}
@@ -88,7 +86,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
* @throws NotFoundExceptionInterface
* @throws Exception
*/
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): void
{
$dispatch = \Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnWorkerError($server, $worker_id, $worker_pid, $exit_code, $signal));
@@ -97,7 +95,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
$worker_id, $worker_pid, $signal, $exit_code, swoole_strerror(swoole_last_error(), 9)
);
\Kiri::getLogger()->error($message);
error($message);
$this->system_mail($message);
}
@@ -107,7 +105,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
* @param $messageContent
* @throws Exception
*/
protected function system_mail($messageContent)
protected function system_mail($messageContent): void
{
try {
$email = Config::get('email', ['enable' => false]);