改名
This commit is contained in:
@@ -10,7 +10,6 @@ use Kiri\Abstracts\Config;
|
||||
use Kiri\Di\NoteManager;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Kiri\Runtime;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use ReflectionException;
|
||||
use Server\ServerManager;
|
||||
@@ -22,15 +21,15 @@ class OnWorkerStart implements EventDispatcherInterface
|
||||
/**
|
||||
* @var Annotation
|
||||
*/
|
||||
#[Inject(Annotation::class)]
|
||||
public Annotation $annotation;
|
||||
#[Inject(Annotation::class)]
|
||||
public Annotation $annotation;
|
||||
|
||||
|
||||
/**
|
||||
* @var Router
|
||||
*/
|
||||
#[Inject(Router::class)]
|
||||
public Router $router;
|
||||
#[Inject(Router::class)]
|
||||
public Router $router;
|
||||
|
||||
|
||||
/**
|
||||
@@ -40,68 +39,67 @@ class OnWorkerStart implements EventDispatcherInterface
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(object $event)
|
||||
{
|
||||
$isWorker = $event->workerId < $event->server->setting['worker_num'];
|
||||
public function dispatch(object $event)
|
||||
{
|
||||
$isWorker = $event->workerId < $event->server->setting['worker_num'];
|
||||
|
||||
$this->annotation->read(APP_PATH . 'app', 'App');
|
||||
$this->interpretDirectory();
|
||||
if ($isWorker) {
|
||||
ServerManager::setEnv('environmental', Kiri::WORKER);
|
||||
Kiri::getFactory()->getRouter()->_loader();
|
||||
$this->interpretDirectory();
|
||||
if ($isWorker) {
|
||||
ServerManager::setEnv('environmental', Kiri::WORKER);
|
||||
Kiri::getFactory()->getRouter()->_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;
|
||||
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));
|
||||
} else {
|
||||
ServerManager::setEnv('environmental', Kiri::TASK);
|
||||
$this->setProcessName(sprintf('Worker[%d].%d', $event->server->worker_pid, $event->workerId));
|
||||
} else {
|
||||
ServerManager::setEnv('environmental', Kiri::TASK);
|
||||
|
||||
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;
|
||||
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));
|
||||
}
|
||||
}
|
||||
$this->setProcessName(sprintf('Tasker[%d].%d', $event->server->worker_pid, $event->workerId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $prefix
|
||||
* @throws ConfigException
|
||||
*/
|
||||
protected function setProcessName($prefix)
|
||||
{
|
||||
if (Kiri::getPlatform()->isMac()) {
|
||||
return;
|
||||
}
|
||||
$name = Config::get('id', 'system-service');
|
||||
if (!empty($prefix)) {
|
||||
$name .= '.' . $prefix;
|
||||
}
|
||||
swoole_set_process_name($name);
|
||||
}
|
||||
/**
|
||||
* @param $prefix
|
||||
* @throws ConfigException
|
||||
*/
|
||||
protected function setProcessName($prefix)
|
||||
{
|
||||
if (Kiri::getPlatform()->isMac()) {
|
||||
return;
|
||||
}
|
||||
$name = Config::get('id', 'system-service');
|
||||
if (!empty($prefix)) {
|
||||
$name .= '.' . $prefix;
|
||||
}
|
||||
swoole_set_process_name($name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function interpretDirectory()
|
||||
{
|
||||
$fileLists = $this->annotation->runtime(APP_PATH . 'app');
|
||||
$di = Kiri::getDi();
|
||||
foreach ($fileLists as $class) {
|
||||
foreach (NoteManager::getTargetNote($class) as $value) {
|
||||
$value->execute($class);
|
||||
}
|
||||
$methods = $di->getMethodAttribute($class);
|
||||
foreach ($methods as $method => $attribute) {
|
||||
if (empty($attribute)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($attribute as $item) {
|
||||
$item->execute($class, $method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function interpretDirectory()
|
||||
{
|
||||
$di = Kiri::getDi();
|
||||
$fileLists = $this->annotation->read(APP_PATH . 'app');
|
||||
foreach ($fileLists->runtime(APP_PATH . 'app') as $class) {
|
||||
foreach (NoteManager::getTargetNote($class) as $value) {
|
||||
$value->execute($class);
|
||||
}
|
||||
$methods = $di->getMethodAttribute($class);
|
||||
foreach ($methods as $method => $attribute) {
|
||||
if (empty($attribute)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($attribute as $item) {
|
||||
$item->execute($class, $method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user