This commit is contained in:
xl
2024-08-29 17:01:07 +08:00
parent b14b18040b
commit 917e82064a
8 changed files with 34 additions and 75 deletions
+4 -11
View File
@@ -35,13 +35,6 @@ class AsyncServer implements ServerInterface
private ?Server $server = null;
/**
* @var ContainerInterface
*/
#[Container(ContainerInterface::class)]
public ContainerInterface $container;
/**
* @param array $service
* @param int $daemon
@@ -110,7 +103,7 @@ class AsyncServer implements ServerInterface
$config->events[Constant::SHUTDOWN] = [OnServer::class, 'onShutdown'];
}
$this->_listenDump($config);
$this->container->bind(ServerInterface::class, $this->server);
\Kiri::getDi()->bind(ServerInterface::class, $this->server);
}
@@ -123,7 +116,7 @@ class AsyncServer implements ServerInterface
if (!isset($this->server->setting[Constant::OPTION_TASK_WORKER_NUM])) {
return;
}
$this->container->get(Task::class)->initTaskWorker($this->server);
\Kiri::getDi()->get(Task::class)->initTaskWorker($this->server);
}
@@ -170,7 +163,7 @@ class AsyncServer implements ServerInterface
*/
protected function _listenDump(SConfig $config): void
{
$writeln = $this->container->get(OutputInterface::class);
$writeln = \Kiri::getDi()->get(OutputInterface::class);
if ($config->type == Constant::SERVER_TYPE_HTTP) {
$writeln->writeln('Add http port listen ' . $config->host . '::' . $config->port);
} else if ($config->type == Constant::SERVER_TYPE_WEBSOCKET) {
@@ -214,7 +207,7 @@ class AsyncServer implements ServerInterface
{
foreach ($events as $name => $event) {
if (is_array($event) && is_string($event[0])) {
$event[0] = $this->container->get($event[0]);
$event[0] = \Kiri::getDi()->get($event[0]);
}
$base->on($name, $event);
}
+1 -15
View File
@@ -44,20 +44,6 @@ abstract class BaseProcess implements OnProcessInterface
protected bool $enable_queue = false;
/**
* @var StdoutLogger
*/
#[Container(LoggerInterface::class)]
public StdoutLogger $logger;
/**
* @var \Kiri\Di\Container
*/
#[Container(ContainerInterface::class)]
public \Kiri\Di\Container $container;
/**
* @var string
*/
@@ -141,7 +127,7 @@ abstract class BaseProcess implements OnProcessInterface
{
$this->stop = true;
$value = Context::get('waite:process:message');
$this->logger->alert('Process ' . $this->getName() . ' stop');
\Kiri::getLogger()->alert('Process ' . $this->getName() . ' stop');
if (!is_null($value) && Coroutine::exists((int)$value)) {
Coroutine::cancel((int)$value);
}
+2 -9
View File
@@ -24,13 +24,6 @@ trait TraitServer
private array $_process = [];
/**
* @var StdoutLogger
*/
#[Container(LoggerInterface::class)]
public StdoutLogger $logger;
/**
* @param string|array|BaseProcess $class
* @return void
@@ -64,7 +57,7 @@ trait TraitServer
private function genProcess(BaseProcess $name): Process
{
return new Process(function (Process $process) use ($name) {
$process->name('[' . \config('id','system-service') . ']' . $name->getName());
$process->name('[' . \config('id','system-service') . '].' . $name->getName());
$name->onSigterm()->process($process);
},
$name->getRedirectStdinAndStdout(),
@@ -111,7 +104,7 @@ trait TraitServer
public function onSigint($no, array $signInfo): void
{
try {
$this->logger->alert('Pid ' . getmypid() . ' get signo ' . $no);
Kiri::getLogger()->alert('Pid ' . getmypid() . ' get signo ' . $no);
$this->shutdown();
} catch (\Throwable $exception) {
error($exception);