This commit is contained in:
as2252258@163.com
2021-08-29 00:58:54 +08:00
parent 300ebfec7d
commit e3f02b51bc
4 changed files with 1056 additions and 1015 deletions
+2 -5
View File
@@ -125,7 +125,7 @@ class Application extends BaseApplication
$manager = $this->getServer();
$manager->addProcess(FileChangeCustomProcess::class);
putenv('enableFileChange=on');
enable_file_modification_listening();
}
@@ -227,11 +227,8 @@ class Application extends BaseApplication
*/
private function enableFileChange($class): void
{
if (env('enableFileChange', 'off') == 'off' || !($class instanceof Command)) {
if (!($class instanceof Command)) {
scan_directory(directory('app'), 'App');
$loader = Kiri::app()->getRouter();
$loader->_loader();
}
}
+38
View File
@@ -56,6 +56,44 @@ if (!function_exists('make')) {
}
if (!function_exists('enable_file_modification_listening')) {
function enable_file_modification_listening(): void
{
putenv('enable_file_modification_listening=on');
}
}
if (!function_exists('is_enable_file_modification_listening')) {
/**
* @return bool
*/
function is_enable_file_modification_listening(): bool
{
return env('enable_file_modification_listening', 'off') == 'off';
}
}
if (!function_exists('disable_file_modification_listening')) {
function disable_file_modification_listening()
{
putenv('enable_file_modification_listening=off');
}
}
if (!function_exists('now')) {
/**
+13 -7
View File
@@ -41,23 +41,29 @@ class Command extends \Console\Command
if ($manager->isRunner() && $dtl->get('action') == 'start') {
return 'Service is running. Please use restart.';
}
$manager->shutdown();
if ($dtl->get('action') == 'stop') {
return 'shutdown success.';
}
$this->generate_runtime_builder();
return $manager->start();
return $this->generate_runtime_builder($manager);
}
/**
*
* @param $manager
* @return mixed
* @throws \Kiri\Exception\NotFindClassException
* @throws \ReflectionException
*/
private function generate_runtime_builder()
private function generate_runtime_builder($manager)
{
exec(PHP_BINARY . ' ' . APP_PATH . 'snowflake 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();
}
return $manager->start();
}
}
+6 -6
View File
@@ -69,7 +69,7 @@ class OnServerWorker extends \Server\Abstracts\Server
Config::sets(unserialize($serialize));
}
$this->workerInitExecutor($server, $workerId);
if (env('enableFileChange', 'off') == 'off') {
if (is_enable_file_modification_listening()) {
$annotation = Kiri::app()->getAnnotation();
$annotation->read(APP_PATH . 'app', 'App',
$workerId < $server->setting['worker_num'] ? [] : [CONTROLLER_PATH]
@@ -115,15 +115,15 @@ class OnServerWorker extends \Server\Abstracts\Server
private function workerInitExecutor(Server $server, int $workerId)
{
if ($workerId < $server->setting['worker_num']) {
if (env('enableFileChange', 'off') == 'off') {
$loader = Kiri::app()->getRouter();
$loader->_loader();
}
putenv('environmental=' . Kiri::WORKER);
echo sprintf("\033[36m[" . date('Y-m-d H:i:s') . "]\033[0m Worker[%d].%d start.", $server->worker_pid, $workerId) . PHP_EOL;
$this->setProcessName(sprintf('Worker[%d].%d', $server->worker_pid, $workerId));
if (is_enable_file_modification_listening()) {
$loader = Kiri::app()->getRouter();
$loader->_loader();
}
} else {
putenv('environmental=' . Kiri::TASK);