Compare commits

...

2 Commits

Author SHA1 Message Date
as2252258 dabcea452a 改名 2021-12-23 18:25:31 +08:00
as2252258 2feda943af 改名 2021-12-23 18:22:26 +08:00
7 changed files with 30 additions and 16 deletions
+4
View File
@@ -5,6 +5,7 @@ namespace Server\Handler;
use Note\Inject;
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
use ReflectionException;
use Server\Abstracts\Server;
use Server\Events\OnBeforeShutdown;
use Server\Events\OnShutdown;
@@ -28,6 +29,7 @@ class OnServer extends Server
/**
* @param \Swoole\Server $server
* @throws ConfigException
* @throws ReflectionException
*/
public function onStart(\Swoole\Server $server)
{
@@ -39,6 +41,7 @@ class OnServer extends Server
/**
* @param \Swoole\Server $server
* @throws ReflectionException
*/
public function onBeforeShutdown(\Swoole\Server $server)
{
@@ -48,6 +51,7 @@ class OnServer extends Server
/**
* @param \Swoole\Server $server
* @throws ReflectionException
*/
public function onShutdown(\Swoole\Server $server)
{
+4 -2
View File
@@ -4,6 +4,7 @@ namespace Server\Handler;
use Note\Inject;
use Kiri\Events\EventDispatch;
use ReflectionException;
use Server\Abstracts\Server;
use Kiri\Exception\ConfigException;
use Server\Events\OnManagerStart;
@@ -26,8 +27,8 @@ class OnServerManager extends Server
/**
* @param \Swoole\Server $server
* @throws ConfigException
*/
* @throws ConfigException|ReflectionException
*/
public function onManagerStart(\Swoole\Server $server)
{
$this->setProcessName(sprintf('manger[%d].0', $server->manager_pid));
@@ -38,6 +39,7 @@ class OnServerManager extends Server
/**
* @param \Swoole\Server $server
* @throws ReflectionException
*/
public function onManagerStop(\Swoole\Server $server)
{
+2
View File
@@ -25,6 +25,7 @@ class OnServerReload
/**
* @param Server $server
* @throws \ReflectionException
*/
public function onBeforeReload(Server $server)
{
@@ -34,6 +35,7 @@ class OnServerReload
/**
* @param Server $server
* @throws \ReflectionException
*/
public function onAfterReload(Server $server)
{
+7 -7
View File
@@ -2,12 +2,12 @@
namespace Server\Handler;
use Note\Inject;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Core\Help;
use Kiri\Events\EventDispatch;
use Kiri\Kiri;
use Note\Inject;
use Server\Events\OnAfterWorkerStart;
use Server\Events\OnBeforeWorkerStart;
use Server\Events\OnTaskerStart as OnTaskStart;
@@ -62,8 +62,8 @@ class OnServerWorker extends \Server\Abstracts\Server
*/
public function onWorkerStop(Server $server, int $workerId)
{
Timer::clearAll();
$this->eventDispatch->dispatch(new OnWorkerStop($server, $workerId));
Timer::clearAll();
$this->eventDispatch->dispatch(new OnWorkerStop($server, $workerId));
}
@@ -76,8 +76,8 @@ class OnServerWorker extends \Server\Abstracts\Server
{
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->system_mail($message);
$this->system_mail($message);
}
@@ -109,7 +109,7 @@ class OnServerWorker extends \Server\Abstracts\Server
protected function system_mail($messageContent)
{
try {
$email = Config::get('email');
$email = Config::get('email', ['enable' => false]);
if (!empty($email) && ($email['enable'] ?? false) == true) {
Help::sendEmail($email, 'Service Error', $messageContent);
}
+6
View File
@@ -10,6 +10,8 @@ use Kiri\Abstracts\Config;
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Server\Events\OnServerBeforeStart;
use Swoole\Coroutine;
use Symfony\Component\Console\Command\Command;
@@ -52,6 +54,10 @@ class ServerCommand extends Command
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws ConfigException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws \ReflectionException
* @throws Exception
*/
public function execute(InputInterface $input, OutputInterface $output): int
+7 -6
View File
@@ -5,7 +5,6 @@ namespace Server;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config;
use Kiri\Di\NoteManager;
use Kiri\Error\Logger;
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
@@ -160,15 +159,17 @@ class ServerManager extends Component
$customProcess = Kiri::getDi()->get($customProcess);
}
$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()) {
$process->name($system . '(' . $customProcess->getName() . ')');
}
$customProcess->onSigterm()->process($process);
}, $customProcess->getRedirectStdinAndStdout(), $customProcess->getPipeType(), $customProcess->isEnableCoroutine());
$this->logger->debug($system . ' ' . $customProcess->getName() . ' start.');
$this->initProcesses[$customProcess->getName()] = $process;
$this->server->addProcess($process);
},
$customProcess->getRedirectStdinAndStdout(),
$customProcess->getPipeType(),
$customProcess->isEnableCoroutine()
));
}
-1
View File
@@ -7,7 +7,6 @@ namespace Server\Tasker;
use Note\Inject;
use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException;
use ReflectionException;
use Server\Contract\OnTaskInterface;
use Swoole\Server;