Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 526256302d | |||
| 95254ac300 | |||
| fdf7757b6a | |||
| 6e4a045c7d | |||
| 03d16d8157 | |||
| c8041cc09e | |||
| 976f67a838 | |||
| c7e0cd4948 |
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace Kiri\Actor;
|
namespace Kiri\Actor;
|
||||||
|
|
||||||
use Kiri\Server\Abstracts\BaseProcess;
|
use Kiri\Server\Processes\AbstractProcess;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Swoole\Process;
|
use Swoole\Process;
|
||||||
|
|
||||||
class ActorProcess extends BaseProcess
|
class ActorProcess extends AbstractProcess
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,7 +21,7 @@ class ActorProcess extends BaseProcess
|
|||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
// TODO: Change the autogenerated stub
|
// TODO: Change the autogenerated stub
|
||||||
return '[' . \config('id', 'system-service') . '].Actor Manager';
|
return 'Actor Manager';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -39,17 +39,9 @@ class ActorProcess extends BaseProcess
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return $this
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function onSigterm(): static
|
public function onSigterm(): void
|
||||||
{
|
{
|
||||||
// TODO: Implement onSigterm() method.
|
|
||||||
Coroutine::create(function () {
|
|
||||||
$sign = Coroutine::waitSignal(SIGINT | SIGTERM);
|
|
||||||
if ($sign) {
|
|
||||||
$this->onShutdown(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,11 +14,16 @@ use Exception;
|
|||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Kiri\Error\StdoutLogger;
|
use Kiri\Error\StdoutLogger;
|
||||||
use ReflectionException;
|
use Kiri\Events\EventDispatch;
|
||||||
|
use Kiri\Events\EventProvider;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Component
|
* Class Component
|
||||||
* @package Kiri\Base
|
* @package Kiri\Base
|
||||||
|
* @property ContainerInterface $container
|
||||||
|
* @property EventDispatch $dispatch
|
||||||
|
* @property EventProvider $provider
|
||||||
*/
|
*/
|
||||||
class Component implements Configure
|
class Component implements Configure
|
||||||
{
|
{
|
||||||
@@ -96,4 +101,29 @@ class Component implements Configure
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return EventDispatch
|
||||||
|
*/
|
||||||
|
public function getDispatch(): EventDispatch
|
||||||
|
{
|
||||||
|
return Kiri::getDi()->get(EventDispatch::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return EventProvider
|
||||||
|
*/
|
||||||
|
public function getProvider(): EventProvider
|
||||||
|
{
|
||||||
|
return Kiri::getDi()->get(EventProvider::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ContainerInterface
|
||||||
|
*/
|
||||||
|
public function getContainer(): ContainerInterface
|
||||||
|
{
|
||||||
|
return Kiri::getDi();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,24 +4,11 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Abstracts;
|
namespace Kiri\Abstracts;
|
||||||
|
|
||||||
|
|
||||||
use Kiri;
|
|
||||||
use Psr\Container\ContainerInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Providers
|
* Class Providers
|
||||||
* @package Kiri\Abstracts
|
* @package Kiri\Abstracts
|
||||||
* @property-read ContainerInterface $container
|
|
||||||
*/
|
*/
|
||||||
abstract class Providers extends Component implements Provider
|
abstract class Providers extends Component implements Provider
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return ContainerInterface
|
|
||||||
*/
|
|
||||||
public function getContainer(): ContainerInterface
|
|
||||||
{
|
|
||||||
return Kiri::getDi();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,13 +34,6 @@ class ErrorHandler extends Component implements ErrorInterface
|
|||||||
public string $category = 'app';
|
public string $category = 'app';
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ContainerInterface
|
|
||||||
*/
|
|
||||||
#[Container(ContainerInterface::class)]
|
|
||||||
public ContainerInterface $container;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|Closure|null $callback
|
* @param array|Closure|null $callback
|
||||||
* @return void
|
* @return void
|
||||||
@@ -51,7 +44,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
|||||||
if (empty($callback)) {
|
if (empty($callback)) {
|
||||||
$callback = [$this, 'exceptionHandler'];
|
$callback = [$this, 'exceptionHandler'];
|
||||||
} else if (is_array($callback) && is_string($callback[0])) {
|
} else if (is_array($callback) && is_string($callback[0])) {
|
||||||
$callback[0] = $this->container->get($callback[0]);
|
$callback[0] = \Kiri::getDi()->get($callback[0]);
|
||||||
}
|
}
|
||||||
set_exception_handler($callback);
|
set_exception_handler($callback);
|
||||||
}
|
}
|
||||||
@@ -67,7 +60,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
|||||||
if (empty($callback)) {
|
if (empty($callback)) {
|
||||||
$callback = [$this, 'errorHandler'];
|
$callback = [$this, 'errorHandler'];
|
||||||
} else if (is_array($callback) && is_string($callback[0])) {
|
} else if (is_array($callback) && is_string($callback[0])) {
|
||||||
$callback[0] = $this->container->get($callback[0]);
|
$callback[0] = \Kiri::getDi()->get($callback[0]);
|
||||||
}
|
}
|
||||||
set_error_handler($callback);
|
set_error_handler($callback);
|
||||||
}
|
}
|
||||||
@@ -83,7 +76,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
|||||||
if (empty($callback)) {
|
if (empty($callback)) {
|
||||||
$callback = [$this, 'shutdown'];
|
$callback = [$this, 'shutdown'];
|
||||||
} else if (is_array($callback) && is_string($callback[0])) {
|
} else if (is_array($callback) && is_string($callback[0])) {
|
||||||
$callback[0] = $this->container->get($callback[0]);
|
$callback[0] = \Kiri::getDi()->get($callback[0]);
|
||||||
}
|
}
|
||||||
register_shutdown_function($callback);
|
register_shutdown_function($callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Kiri;
|
|||||||
use Kiri\Exception\RedisConnectException;
|
use Kiri\Exception\RedisConnectException;
|
||||||
use Kiri\Pool\Pool;
|
use Kiri\Pool\Pool;
|
||||||
use RedisException;
|
use RedisException;
|
||||||
|
use wchat\common\Result;
|
||||||
use function config;
|
use function config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,7 +134,7 @@ SCRIPT;
|
|||||||
*/
|
*/
|
||||||
public function destroy(): void
|
public function destroy(): void
|
||||||
{
|
{
|
||||||
$this->pool()->close($this->host);
|
$this->pool()->close($this->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ SCRIPT;
|
|||||||
return trigger_print_error(throwable($throwable));
|
return trigger_print_error(throwable($throwable));
|
||||||
} finally {
|
} finally {
|
||||||
if ($client->ping('h') == 'h') {
|
if ($client->ping('h') == 'h') {
|
||||||
$this->pool()->push($this->host, $client);
|
$this->pool()->push($this->getName(), $client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +165,7 @@ SCRIPT;
|
|||||||
*/
|
*/
|
||||||
private function getClient(): \Redis
|
private function getClient(): \Redis
|
||||||
{
|
{
|
||||||
return $this->pool()->get($this->host);
|
return $this->pool()->get($this->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -175,13 +176,22 @@ SCRIPT;
|
|||||||
protected function pool(): Pool
|
protected function pool(): Pool
|
||||||
{
|
{
|
||||||
$pool = Kiri::getPool();
|
$pool = Kiri::getPool();
|
||||||
if (!$pool->hasChannel($this->host)) {
|
if (!$pool->hasChannel($this->getName())) {
|
||||||
$pool->created($this->host, $this->pool['max'], [$this, 'connect']);
|
$pool->created($this->getName(), $this->pool['max'], [$this, 'connect']);
|
||||||
}
|
}
|
||||||
return $pool;
|
return $pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getName(): string
|
||||||
|
{
|
||||||
|
return 'redis.' . $this->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Redis
|
* @return \Redis
|
||||||
* @throws
|
* @throws
|
||||||
|
|||||||
Reference in New Issue
Block a user