111
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
namespace Http;
|
namespace Http;
|
||||||
|
|
||||||
|
|
||||||
|
use Annotation\Inject;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Abstracts\Input;
|
use Kiri\Abstracts\Input;
|
||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
@@ -28,6 +29,13 @@ class Command extends \Console\Command
|
|||||||
const ACTIONS = ['start', 'stop', 'restart'];
|
const ACTIONS = ['start', 'stop', 'restart'];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Kiri\Events\EventProvider
|
||||||
|
*/
|
||||||
|
#[Inject(EventProvider::class)]
|
||||||
|
public EventProvider $eventProvider;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Input $dtl
|
* @param Input $dtl
|
||||||
* @return string
|
* @return string
|
||||||
@@ -61,14 +69,8 @@ class Command extends \Console\Command
|
|||||||
private function generate_runtime_builder($manager)
|
private function generate_runtime_builder($manager)
|
||||||
{
|
{
|
||||||
exec(PHP_BINARY . ' ' . APP_PATH . 'kiri.php runtime:builder');
|
exec(PHP_BINARY . ' ' . APP_PATH . 'kiri.php runtime:builder');
|
||||||
if (!is_enable_file_modification_listening()) {
|
|
||||||
scan_directory(directory('app'), 'App');
|
|
||||||
$loader = Kiri::app()->getRouter();
|
|
||||||
$loader->_loader();
|
|
||||||
}
|
|
||||||
|
|
||||||
$event = di(EventProvider::class);
|
$this->eventProvider->on(OnWorkerStart::class, [WorkerDispatch::class, 'dispatch']);
|
||||||
$event->on(OnWorkerStart::class, [di(WorkerDispatch::class), 'dispatch']);
|
|
||||||
|
|
||||||
return $manager->start();
|
return $manager->start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
namespace Server\Worker;
|
namespace Server\Worker;
|
||||||
|
|
||||||
use Annotation\Annotation;
|
use Annotation\Annotation;
|
||||||
|
use Annotation\Inject;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Http\Route\Router;
|
||||||
use Kiri\Abstracts\Config;
|
use Kiri\Abstracts\Config;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
@@ -16,17 +18,12 @@ class OnWorkerStart implements EventDispatcherInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
#[Inject(Annotation::class)]
|
||||||
public Annotation $annotation;
|
public Annotation $annotation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
#[Inject(Router::class)]
|
||||||
* @param \Server\Events\OnWorkerStart $onWorkerStart
|
public Router $router;
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->annotation = Kiri::app()->getAnnotation();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,51 +40,25 @@ class OnWorkerStart implements EventDispatcherInterface
|
|||||||
if (!empty($serialize)) {
|
if (!empty($serialize)) {
|
||||||
Config::sets(unserialize($serialize));
|
Config::sets(unserialize($serialize));
|
||||||
}
|
}
|
||||||
if ($event->workerId < $event->server->setting['worker_num']) {
|
|
||||||
$this->onWorkerInit($event);
|
$isWorker = $event->workerId < $event->server->setting['worker_num'];
|
||||||
} else {
|
|
||||||
$this->onTaskInit($event);
|
$this->annotation->read(APP_PATH . 'app','App', $isWorker ? [] : [CONTROLLER_PATH]);
|
||||||
}
|
|
||||||
$this->interpretDirectory();
|
$this->interpretDirectory();
|
||||||
}
|
if ($isWorker) {
|
||||||
|
putenv('environmental=' . Kiri::WORKER);
|
||||||
|
$this->router->_loader();
|
||||||
|
|
||||||
|
echo sprintf("\033[36m[" . date('Y-m-d H:i:s') . "]\033[0m Worker[%d].%d start.", $event->server->worker_pid, $event->workerId) . PHP_EOL;
|
||||||
|
|
||||||
/**
|
$this->setProcessName(sprintf('Worker[%d].%d', $event->server->worker_pid, $event->workerId));
|
||||||
* @param $event
|
} else {
|
||||||
* @throws \Kiri\Exception\ConfigException
|
putenv('environmental=' . Kiri::TASK);
|
||||||
* @throws \Exception
|
|
||||||
*/
|
echo sprintf("\033[36m[" . date('Y-m-d H:i:s') . "]\033[0m Tasker[%d].%d start.", $event->server->worker_pid, $event->workerId) . PHP_EOL;
|
||||||
public function onTaskInit($event)
|
|
||||||
{
|
$this->setProcessName(sprintf('Tasker[%d].%d', $event->server->worker_pid, $event->workerId));
|
||||||
putenv('environmental=' . Kiri::TASK);
|
|
||||||
if (is_enable_file_modification_listening()) {
|
|
||||||
$this->annotation->read(APP_PATH . 'app', 'App', [CONTROLLER_PATH]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo sprintf("\033[36m[" . date('Y-m-d H:i:s') . "]\033[0m Tasker[%d].%d start.", $event->server->worker_pid, $event->workerId) . PHP_EOL;
|
|
||||||
|
|
||||||
$this->setProcessName(sprintf('Tasker[%d].%d', $event->server->worker_pid, $event->workerId));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $event
|
|
||||||
* @throws \Kiri\Exception\ConfigException
|
|
||||||
* @throws \ReflectionException
|
|
||||||
*/
|
|
||||||
public function onWorkerInit($event)
|
|
||||||
{
|
|
||||||
putenv('environmental=' . Kiri::WORKER);
|
|
||||||
|
|
||||||
if (is_enable_file_modification_listening()) {
|
|
||||||
$this->annotation->read(APP_PATH . 'app');
|
|
||||||
$loader = Kiri::app()->getRouter();
|
|
||||||
$loader->_loader();
|
|
||||||
}
|
|
||||||
|
|
||||||
echo sprintf("\033[36m[" . date('Y-m-d H:i:s') . "]\033[0m Worker[%d].%d start.", $event->server->worker_pid, $event->workerId) . PHP_EOL;
|
|
||||||
|
|
||||||
$this->setProcessName(sprintf('Worker[%d].%d', $event->server->worker_pid, $event->workerId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user