Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 845b8b36d1 | |||
| 07436f7035 | |||
| 4d93fcaff2 | |||
| 2e01b60e1e | |||
| 8d2ce1d45c | |||
| 8a3ed5aea5 | |||
| d50b6e6ec7 |
+5
-7
@@ -7,14 +7,15 @@ use Http\Handler\Handler;
|
||||
use Http\Handler\Router;
|
||||
use Http\Message\ServerRequest;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Consul\Agent;
|
||||
use Kiri\Context;
|
||||
use Kiri\Events\EventProvider;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Note\Inject;
|
||||
use Note\Note;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use ReflectionException;
|
||||
@@ -50,10 +51,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
public EventProvider $eventProvider;
|
||||
|
||||
|
||||
#[Inject(ContainerInterface::class)]
|
||||
public ContainerInterface $container;
|
||||
|
||||
|
||||
private RpcManager $manager;
|
||||
|
||||
/**
|
||||
@@ -67,7 +64,6 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
scan_directory(APP_PATH . 'rpc', 'Rpc');
|
||||
|
||||
$this->eventProvider->on(OnWorkerStart::class, [$this, 'consulWatches']);
|
||||
$this->eventProvider->on(OnTaskerStart::class, [$this, 'consulWatches']);
|
||||
$this->eventProvider->on(OnServerBeforeStart::class, [$this, 'register']);
|
||||
|
||||
$this->manager = Kiri::getDi()->get(RpcManager::class);
|
||||
@@ -92,13 +88,15 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
|
||||
|
||||
/**
|
||||
* @param OnWorkerStart|OnTaskerStart $server
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function consulWatches(OnWorkerStart|OnTaskerStart $server)
|
||||
{
|
||||
if ($server->workerId != 0) {
|
||||
return;
|
||||
}
|
||||
Timer::tick(1000, static function ($timeId) {
|
||||
$async_time = (int)Config::get('consul.async_time', 1000);
|
||||
Timer::tick($async_time, static function ($timeId) {
|
||||
if (env('state', 'start') == 'exit') {
|
||||
Timer::clear($timeId);
|
||||
return;
|
||||
|
||||
+5
-2
@@ -3,12 +3,13 @@
|
||||
namespace Kiri\Rpc;
|
||||
|
||||
use Http\Handler\Handler;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Consul\Agent;
|
||||
use Kiri\Consul\Health;
|
||||
use Kiri\Kiri;
|
||||
use ReflectionException;
|
||||
|
||||
class RpcManager
|
||||
class RpcManager extends Component
|
||||
{
|
||||
|
||||
|
||||
@@ -87,8 +88,10 @@ class RpcManager
|
||||
}
|
||||
|
||||
foreach ($lists as $reflection) {
|
||||
if ($reflection->getDeclaringClass() != $class) {
|
||||
continue;
|
||||
}
|
||||
$methodName = $reflection->getName();
|
||||
|
||||
$this->_rpc[$name]['methods'][$methodName] = [new Handler('/', [$class, $methodName]), null];
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user