Compare commits

...

4 Commits

Author SHA1 Message Date
as2252258 80cf72adc9 Revert "改名"
This reverts commit fdf58326
2022-01-04 16:06:29 +08:00
as2252258 dabcea452a 改名 2021-12-23 18:25:31 +08:00
as2252258 2feda943af 改名 2021-12-23 18:22:26 +08:00
as2252258 bffe375230 1 2021-12-17 04:20:20 +08:00
8 changed files with 35 additions and 27 deletions
+5 -5
View File
@@ -17,7 +17,7 @@ abstract class BaseProcess implements OnProcessInterface
protected bool $isStop = false; protected bool $isStop = false;
protected mixed $redirect_stdin_and_stdout = null; protected bool $redirect_stdin_and_stdout = FALSE;
protected int $pipe_type = SOCK_DGRAM; protected int $pipe_type = SOCK_DGRAM;
@@ -47,10 +47,10 @@ abstract class BaseProcess implements OnProcessInterface
} }
/** /**
* @return mixed * @return bool
*/ */
public function getRedirectStdinAndStdout(): mixed public function getRedirectStdinAndStdout(): bool
{ {
return $this->redirect_stdin_and_stdout; return $this->redirect_stdin_and_stdout;
} }
+4
View File
@@ -5,6 +5,7 @@ namespace Server\Handler;
use Note\Inject; use Note\Inject;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use ReflectionException;
use Server\Abstracts\Server; use Server\Abstracts\Server;
use Server\Events\OnBeforeShutdown; use Server\Events\OnBeforeShutdown;
use Server\Events\OnShutdown; use Server\Events\OnShutdown;
@@ -28,6 +29,7 @@ class OnServer extends Server
/** /**
* @param \Swoole\Server $server * @param \Swoole\Server $server
* @throws ConfigException * @throws ConfigException
* @throws ReflectionException
*/ */
public function onStart(\Swoole\Server $server) public function onStart(\Swoole\Server $server)
{ {
@@ -39,6 +41,7 @@ class OnServer extends Server
/** /**
* @param \Swoole\Server $server * @param \Swoole\Server $server
* @throws ReflectionException
*/ */
public function onBeforeShutdown(\Swoole\Server $server) public function onBeforeShutdown(\Swoole\Server $server)
{ {
@@ -48,6 +51,7 @@ class OnServer extends Server
/** /**
* @param \Swoole\Server $server * @param \Swoole\Server $server
* @throws ReflectionException
*/ */
public function onShutdown(\Swoole\Server $server) public function onShutdown(\Swoole\Server $server)
{ {
+4 -2
View File
@@ -4,6 +4,7 @@ namespace Server\Handler;
use Note\Inject; use Note\Inject;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use ReflectionException;
use Server\Abstracts\Server; use Server\Abstracts\Server;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Server\Events\OnManagerStart; use Server\Events\OnManagerStart;
@@ -26,8 +27,8 @@ class OnServerManager extends Server
/** /**
* @param \Swoole\Server $server * @param \Swoole\Server $server
* @throws ConfigException * @throws ConfigException|ReflectionException
*/ */
public function onManagerStart(\Swoole\Server $server) public function onManagerStart(\Swoole\Server $server)
{ {
$this->setProcessName(sprintf('manger[%d].0', $server->manager_pid)); $this->setProcessName(sprintf('manger[%d].0', $server->manager_pid));
@@ -38,6 +39,7 @@ class OnServerManager extends Server
/** /**
* @param \Swoole\Server $server * @param \Swoole\Server $server
* @throws ReflectionException
*/ */
public function onManagerStop(\Swoole\Server $server) public function onManagerStop(\Swoole\Server $server)
{ {
+2
View File
@@ -25,6 +25,7 @@ class OnServerReload
/** /**
* @param Server $server * @param Server $server
* @throws \ReflectionException
*/ */
public function onBeforeReload(Server $server) public function onBeforeReload(Server $server)
{ {
@@ -34,6 +35,7 @@ class OnServerReload
/** /**
* @param Server $server * @param Server $server
* @throws \ReflectionException
*/ */
public function onAfterReload(Server $server) public function onAfterReload(Server $server)
{ {
+7 -7
View File
@@ -2,12 +2,12 @@
namespace Server\Handler; namespace Server\Handler;
use Note\Inject;
use Exception; use Exception;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Core\Help; use Kiri\Core\Help;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Kiri; use Kiri\Kiri;
use Note\Inject;
use Server\Events\OnAfterWorkerStart; use Server\Events\OnAfterWorkerStart;
use Server\Events\OnBeforeWorkerStart; use Server\Events\OnBeforeWorkerStart;
use Server\Events\OnTaskerStart as OnTaskStart; use Server\Events\OnTaskerStart as OnTaskStart;
@@ -62,8 +62,8 @@ class OnServerWorker extends \Server\Abstracts\Server
*/ */
public function onWorkerStop(Server $server, int $workerId) public function onWorkerStop(Server $server, int $workerId)
{ {
Timer::clearAll(); Timer::clearAll();
$this->eventDispatch->dispatch(new OnWorkerStop($server, $workerId)); $this->eventDispatch->dispatch(new OnWorkerStop($server, $workerId));
} }
@@ -76,8 +76,8 @@ class OnServerWorker extends \Server\Abstracts\Server
{ {
set_env('state', 'exit'); set_env('state', 'exit');
$this->eventDispatch->dispatch(new OnWorkerExit($server, $workerId)); $this->eventDispatch->dispatch(new OnWorkerExit($server, $workerId));
} }
/** /**
@@ -98,7 +98,7 @@ class OnServerWorker extends \Server\Abstracts\Server
$this->logger->error($message); $this->logger->error($message);
// $this->system_mail($message); $this->system_mail($message);
} }
@@ -109,7 +109,7 @@ class OnServerWorker extends \Server\Abstracts\Server
protected function system_mail($messageContent) protected function system_mail($messageContent)
{ {
try { try {
$email = Config::get('email'); $email = Config::get('email', ['enable' => false]);
if (!empty($email) && ($email['enable'] ?? false) == true) { if (!empty($email) && ($email['enable'] ?? false) == true) {
Help::sendEmail($email, 'Service Error', $messageContent); Help::sendEmail($email, 'Service Error', $messageContent);
} }
+6
View File
@@ -10,6 +10,8 @@ use Kiri\Abstracts\Config;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Kiri; use Kiri\Kiri;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Server\Events\OnServerBeforeStart; use Server\Events\OnServerBeforeStart;
use Swoole\Coroutine; use Swoole\Coroutine;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
@@ -52,6 +54,10 @@ class ServerCommand extends Command
* @param InputInterface $input * @param InputInterface $input
* @param OutputInterface $output * @param OutputInterface $output
* @return int * @return int
* @throws ConfigException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws \ReflectionException
* @throws Exception * @throws Exception
*/ */
public function execute(InputInterface $input, OutputInterface $output): int public function execute(InputInterface $input, OutputInterface $output): int
+7 -12
View File
@@ -5,7 +5,6 @@ namespace Server;
use Exception; use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Di\NoteManager;
use Kiri\Error\Logger; use Kiri\Error\Logger;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
@@ -117,7 +116,6 @@ class ServerManager extends Component
* @throws ConfigException * @throws ConfigException
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
public function addListener(string $type, string $host, int $port, int $mode, array $settings = []) public function addListener(string $type, string $host, int $port, int $mode, array $settings = [])
{ {
@@ -160,15 +158,17 @@ class ServerManager extends Component
$customProcess = Kiri::getDi()->get($customProcess); $customProcess = Kiri::getDi()->get($customProcess);
} }
$system = sprintf('[%s].process', Config::get('id', 'system-service')); $system = sprintf('[%s].process', Config::get('id', 'system-service'));
$process = new Process(function (Process $process) use ($customProcess, $system) { $this->logger->debug($system . ' ' . $customProcess->getName() . ' start.');
$this->server->addProcess(new Process(function (Process $process) use ($customProcess, $system) {
if (Kiri::getPlatform()->isLinux()) { if (Kiri::getPlatform()->isLinux()) {
$process->name($system . '(' . $customProcess->getName() . ')'); $process->name($system . '(' . $customProcess->getName() . ')');
} }
$customProcess->onSigterm()->process($process); $customProcess->onSigterm()->process($process);
}, $customProcess->getRedirectStdinAndStdout(), $customProcess->getPipeType(), $customProcess->isEnableCoroutine()); },
$this->logger->debug($system . ' ' . $customProcess->getName() . ' start.'); $customProcess->getRedirectStdinAndStdout(),
$this->initProcesses[$customProcess->getName()] = $process; $customProcess->getPipeType(),
$this->server->addProcess($process); $customProcess->isEnableCoroutine()
));
} }
@@ -276,7 +276,6 @@ class ServerManager extends Component
* @throws ConfigException * @throws ConfigException
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ReflectionException
* @throws Exception * @throws Exception
*/ */
private function createBaseServer(string $type, string $host, int $port, int $mode, array $settings = []) private function createBaseServer(string $type, string $host, int $port, int $mode, array $settings = [])
@@ -302,7 +301,6 @@ class ServerManager extends Component
* @param array $settings * @param array $settings
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
private function addDefaultListener(array $settings): void private function addDefaultListener(array $settings): void
{ {
@@ -322,7 +320,6 @@ class ServerManager extends Component
* @param Server|Port $server * @param Server|Port $server
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
private function addServiceEvents(array $events, Server|Port $server) private function addServiceEvents(array $events, Server|Port $server)
{ {
@@ -360,7 +357,6 @@ class ServerManager extends Component
* @return void * @return void
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
private function addTaskListener(array $events = []): void private function addTaskListener(array $events = []): void
{ {
@@ -380,7 +376,6 @@ class ServerManager extends Component
* @return void * @return void
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
public function bindCallback(?array $settings = []) public function bindCallback(?array $settings = [])
{ {
-1
View File
@@ -7,7 +7,6 @@ namespace Server\Tasker;
use Note\Inject; use Note\Inject;
use Kiri\Abstracts\Logger; use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use ReflectionException;
use Server\Contract\OnTaskInterface; use Server\Contract\OnTaskInterface;
use Swoole\Server; use Swoole\Server;