This commit is contained in:
2023-08-14 21:09:44 +08:00
parent 8cce9e5a3e
commit 53c06f8fd7
6 changed files with 44 additions and 18 deletions
-3
View File
@@ -4,16 +4,13 @@ namespace Kiri\Server\Abstracts;
use Exception;
use Kiri;
use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException;
use Kiri\Exception\NotFindClassException;
use Kiri\Server\Config as SConfig;
use Kiri\Server\Constant;
use Kiri\Server\Events\OnServerBeforeStart;
use Kiri\Server\Events\OnShutdown;
use Kiri\Server\Events\OnWorkerStart;
use Kiri\Server\Handler\OnServer;
use Kiri\Server\HotReload;
use Kiri\Server\ServerInterface;
use Kiri\Server\Task\TaskInterface;
use Kiri\Server\Task\Task;
+11 -2
View File
@@ -3,9 +3,11 @@
namespace Kiri\Server\Abstracts;
use Kiri\Abstracts\Logger;
use Kiri\Di\Context;
use Kiri\Di\Inject\Container;
use Kiri\Server\Contract\OnProcessInterface;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Swoole\Coroutine;
/**
@@ -26,6 +28,13 @@ abstract class BaseProcess implements OnProcessInterface
protected bool $enable_coroutine = false;
/**
* @var Logger
*/
#[Container(LoggerInterface::class)]
public Logger $logger;
public string $name = '';
@@ -97,7 +106,7 @@ abstract class BaseProcess implements OnProcessInterface
{
$this->isStop = true;
$value = Context::get('waite:process:message');
Logger::_alert('Process ' . $this->getName() . ' stop');
$this->logger->alert('Process ' . $this->getName() . ' stop');
if (!is_null($value) && Coroutine::exists((int)$value)) {
Coroutine::cancel((int)$value);
}
+11 -2
View File
@@ -6,10 +6,12 @@ use Closure;
use Exception;
use Kiri;
use Kiri\Abstracts\Component;
use Kiri\Di\Inject\Container;
use Kiri\Server\Contract\OnProcessInterface;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use ReflectionException;
use Swoole\Process;
use Kiri\Abstracts\Logger;
use Kiri\Server\ServerInterface;
use Kiri\Server\Events\OnServerBeforeStart;
@@ -17,6 +19,13 @@ class ProcessManager extends Component
{
/**
* @var Logger
*/
#[Container(LoggerInterface::class)]
public Logger $logger;
/** @var array<string, BaseProcess> */
private array $_process = [];
@@ -174,7 +183,7 @@ class ProcessManager extends Component
{
set_env('environmental', Kiri::PROCESS);
$system = sprintf('[%s].Custom Process', \config('id', 'system-service'));
Logger::_alert($system . ' ' . $custom->getName() . ' start.');
$this->logger->alert($system . ' ' . $custom->getName() . ' start.');
if (Kiri::getPlatform()->isLinux()) {
$process->name($system . '[' . $process->pid . '].' . $custom->getName());
}
+12 -4
View File
@@ -4,9 +4,9 @@ namespace Kiri\Server\Abstracts;
use Exception;
use Kiri;
use Kiri\Abstracts\Logger;
use ReflectionException;
use Swoole\Coroutine;
use Kiri\Di\Inject\Container;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Swoole\Http\Server as HServer;
use Swoole\Process;
use Swoole\Server;
@@ -21,6 +21,14 @@ trait TraitServer
private array $_process = [];
/**
* @var Logger
*/
#[Container(LoggerInterface::class)]
public Logger $logger;
/**
* @param string|array|BaseProcess $class
* @return void
@@ -87,7 +95,7 @@ trait TraitServer
public function onSigint($no, array $signInfo): void
{
try {
Logger::_alert('Pid ' . getmypid() . ' get signo ' . $no);
$this->logger->alert('Pid ' . getmypid() . ' get signo ' . $no);
$this->shutdown();
} catch (\Throwable $exception) {
error($exception);
+10 -6
View File
@@ -2,14 +2,11 @@
namespace Kiri\Server\Handler;
use Kiri\Abstracts\Logger;
use Kiri\Di\Inject\Container;
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
use Kiri\Server\Events\OnAfterReload;
use Kiri\Server\Events\OnBeforeReload;
use Monolog\Logger;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use ReflectionException;
use Kiri\Server\Abstracts\Server;
use Kiri\Server\Events\OnBeforeShutdown;
@@ -26,6 +23,13 @@ class OnServer extends Server
{
/**
* @var Logger
*/
#[Container(LoggerInterface::class)]
public Logger $logger;
/**
* @param SServer $server
* @throws ReflectionException
@@ -36,7 +40,7 @@ class OnServer extends Server
{
\Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid));
foreach (config('server.ports') as $value) {
Logger::_alert('Listen ' . $value['type'] . ' address ' . $value['host'] . '::' . $value['port']);
$this->logger->alert('Listen ' . $value['type'] . ' address ' . $value['host'] . '::' . $value['port']);
}
event(new OnStart($server));
}
-1
View File
@@ -4,7 +4,6 @@ namespace Kiri\Server;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Abstracts\Logger;
use Kiri\Server\Abstracts\TraitServer;
use Swoole\Process;