改名
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
namespace Server\Abstracts;
|
namespace Server\Abstracts;
|
||||||
|
|
||||||
|
|
||||||
use JetBrains\PhpStorm\Pure;
|
use Kiri\Context;
|
||||||
use Server\Contract\OnProcessInterface;
|
use Server\Contract\OnProcessInterface;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Swoole\Process;
|
use Swoole\Process;
|
||||||
@@ -80,4 +80,32 @@ abstract class BaseProcess implements OnProcessInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function onSigterm(): static
|
||||||
|
{
|
||||||
|
if (!Context::inCoroutine()) {
|
||||||
|
Process::signal(SIGTERM, fn($data) => $this->onShutdown($data));
|
||||||
|
} else {
|
||||||
|
Coroutine::create(function () {
|
||||||
|
$data = Coroutine::waitSignal(SIGTERM, -1);
|
||||||
|
if ($data) {
|
||||||
|
$this->onShutdown($data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
*/
|
||||||
|
protected function onShutdown($data): void
|
||||||
|
{
|
||||||
|
$this->isStop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-4
@@ -67,6 +67,9 @@ class ServerManager extends Component
|
|||||||
private Server|null $server = null;
|
private Server|null $server = null;
|
||||||
|
|
||||||
|
|
||||||
|
protected array $initProcesses = [];
|
||||||
|
|
||||||
|
|
||||||
const DEFAULT_EVENT = [
|
const DEFAULT_EVENT = [
|
||||||
Constant::WORKER_START => [OnServerWorker::class, 'onWorkerStart'],
|
Constant::WORKER_START => [OnServerWorker::class, 'onWorkerStart'],
|
||||||
Constant::WORKER_EXIT => [OnServerWorker::class, 'onWorkerExit'],
|
Constant::WORKER_EXIT => [OnServerWorker::class, 'onWorkerExit'],
|
||||||
@@ -160,14 +163,23 @@ class ServerManager extends Component
|
|||||||
if (Kiri::getPlatform()->isLinux()) {
|
if (Kiri::getPlatform()->isLinux()) {
|
||||||
$process->name($system . '(' . $customProcess->getName() . ')');
|
$process->name($system . '(' . $customProcess->getName() . ')');
|
||||||
}
|
}
|
||||||
$customProcess->process($process);
|
$customProcess->onSigterm()->process($process);
|
||||||
}, $customProcess->getRedirectStdinAndStdout(), $customProcess->getPipeType(), $customProcess->isEnableCoroutine());
|
}, $customProcess->getRedirectStdinAndStdout(), $customProcess->getPipeType(), $customProcess->isEnableCoroutine());
|
||||||
$this->logger->debug($system . ' ' . $customProcess->getName() . ' start.');
|
$this->logger->debug($system . ' ' . $customProcess->getName() . ' start.');
|
||||||
$this->container->setBindings($customProcess->getName(), $process);
|
$this->initProcesses[$customProcess->getName()] = $process;
|
||||||
$this->server->addProcess($process);
|
$this->server->addProcess($process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string,Process>
|
||||||
|
*/
|
||||||
|
public function getProcesses(): array
|
||||||
|
{
|
||||||
|
return $this->initProcesses;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -346,7 +358,6 @@ class ServerManager extends Component
|
|||||||
* @param array $events
|
* @param array $events
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
private function addTaskListener(array $events = []): void
|
private function addTaskListener(array $events = []): void
|
||||||
{
|
{
|
||||||
@@ -365,7 +376,6 @@ class ServerManager extends Component
|
|||||||
* @param array|null $settings
|
* @param array|null $settings
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public function bindCallback(?array $settings = [])
|
public function bindCallback(?array $settings = [])
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user