Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c19e141f68 | |||
| 94a522588d | |||
| 308c992fd3 | |||
| 458c6cbd22 | |||
| b717a7e9f7 | |||
| 6786b313b5 |
@@ -3,7 +3,7 @@
|
||||
namespace Server\Abstracts;
|
||||
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Kiri\Context;
|
||||
use Server\Contract\OnProcessInterface;
|
||||
use Swoole\Coroutine;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -137,8 +137,9 @@ class Server extends HttpService
|
||||
|
||||
/**
|
||||
* @return \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
#[Pure] public function getServer(): \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
||||
public function getServer(): \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
||||
{
|
||||
return $this->manager->getServer();
|
||||
}
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ class ServerCommand extends Command
|
||||
$this->configure_set();
|
||||
|
||||
Kiri::app()->getRouter()->read_files();
|
||||
|
||||
|
||||
$manager->start();
|
||||
|
||||
return 1;
|
||||
|
||||
+14
-20
@@ -3,15 +3,14 @@
|
||||
namespace Server;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Di\Container;
|
||||
use Kiri\Error\Logger;
|
||||
use Kiri\Events\EventDispatch;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Note\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use ReflectionException;
|
||||
use Server\Abstracts\BaseProcess;
|
||||
@@ -41,7 +40,7 @@ use Swoole\WebSocket\Server as WServer;
|
||||
* Class OnServerManager
|
||||
* @package Http\Service
|
||||
*/
|
||||
class ServerManager
|
||||
class ServerManager extends Component
|
||||
{
|
||||
|
||||
|
||||
@@ -59,14 +58,6 @@ class ServerManager
|
||||
#[Inject(Logger::class)]
|
||||
public Logger $logger;
|
||||
|
||||
|
||||
/**
|
||||
* @var State
|
||||
*/
|
||||
#[Inject(State::class)]
|
||||
public State $state;
|
||||
|
||||
|
||||
/** @var array<string,Port> */
|
||||
public array $ports = [];
|
||||
|
||||
@@ -76,11 +67,7 @@ class ServerManager
|
||||
private Server|null $server = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
#[Inject(ContainerInterface::class)]
|
||||
public ContainerInterface $container;
|
||||
protected array $initProcesses = [];
|
||||
|
||||
|
||||
const DEFAULT_EVENT = [
|
||||
@@ -176,14 +163,23 @@ class ServerManager
|
||||
if (Kiri::getPlatform()->isLinux()) {
|
||||
$process->name($system . '(' . $customProcess->getName() . ')');
|
||||
}
|
||||
$customProcess->process($process);
|
||||
$customProcess->onSigterm()->process($process);
|
||||
}, $customProcess->getRedirectStdinAndStdout(), $customProcess->getPipeType(), $customProcess->isEnableCoroutine());
|
||||
$this->logger->debug($system . ' ' . $customProcess->getName() . ' start.');
|
||||
$this->container->setBindings($customProcess->getName(), $process);
|
||||
$this->initProcesses[$customProcess->getName()] = $process;
|
||||
$this->server->addProcess($process);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array<string,Process>
|
||||
*/
|
||||
public function getProcesses(): array
|
||||
{
|
||||
return $this->initProcesses;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -362,7 +358,6 @@ class ServerManager
|
||||
* @param array $events
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function addTaskListener(array $events = []): void
|
||||
{
|
||||
@@ -381,7 +376,6 @@ class ServerManager
|
||||
* @param array|null $settings
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function bindCallback(?array $settings = [])
|
||||
{
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
namespace Server;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Abstracts\BaseObject;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Swoole\Process;
|
||||
|
||||
class State extends BaseObject
|
||||
class State extends Component
|
||||
{
|
||||
|
||||
use TraitServer;
|
||||
|
||||
@@ -3,12 +3,9 @@
|
||||
namespace Server\Tasker;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Abstracts\BaseObject;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Core\HashMap;
|
||||
use Kiri\Di\Container;
|
||||
use Kiri\Kiri;
|
||||
use Note\Inject;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use ReflectionException;
|
||||
use Server\Contract\OnTaskInterface;
|
||||
use Server\SwooleServerInterface;
|
||||
@@ -17,7 +14,7 @@ use Server\SwooleServerInterface;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class AsyncTaskExecute extends BaseObject
|
||||
class AsyncTaskExecute extends Component
|
||||
{
|
||||
|
||||
|
||||
@@ -27,13 +24,6 @@ class AsyncTaskExecute extends BaseObject
|
||||
public ?SwooleServerInterface $server = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
#[Inject(ContainerInterface::class)]
|
||||
public ContainerInterface $container;
|
||||
|
||||
|
||||
private HashMap $hashMap;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user