This commit is contained in:
2020-11-17 17:41:10 +08:00
parent 8525f499ab
commit 3956a282b8
+14 -16
View File
@@ -13,6 +13,7 @@ namespace Snowflake\Process;
use Exception; use Exception;
use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Config;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use Swoole\Coroutine;
use Swoole\Event; use Swoole\Event;
use Swoole\Timer; use Swoole\Timer;
@@ -51,7 +52,8 @@ class ServerInotify extends Process
$this->loadByDir(APP_PATH . 'app'); $this->loadByDir(APP_PATH . 'app');
$this->loadByDir(APP_PATH . 'routes'); $this->loadByDir(APP_PATH . 'routes');
$this->loadByDir(__DIR__ . '/../../'); $this->loadByDir(__DIR__ . '/../../');
Timer::after(2000, [$this, 'tick']);
$this->tick();
} }
} }
@@ -70,10 +72,14 @@ class ServerInotify extends Process
$this->loadByDir(APP_PATH . 'app', true); $this->loadByDir(APP_PATH . 'app', true);
$this->loadByDir(APP_PATH . 'routes', true); $this->loadByDir(APP_PATH . 'routes', true);
$this->loadByDir(__DIR__ . '/../../', true); $this->loadByDir(__DIR__ . '/../../', true);
Timer::after(2000, [$this, 'tick']);
Coroutine::sleep(3);
$this->tick();
} }
/** /**
* @param $path * @param $path
* @param bool $isReload * @param bool $isReload
@@ -83,25 +89,21 @@ class ServerInotify extends Process
private function loadByDir($path, $isReload = false) private function loadByDir($path, $isReload = false)
{ {
$path = rtrim($path, '/'); $path = rtrim($path, '/');
if ($this->isReloading) { foreach (glob(realpath($path) . '/*') as $value) {
return;
}
foreach (glob($path . '/*') as $value) {
if (is_dir($value)) { if (is_dir($value)) {
$this->loadByDir($value, $isReload); $this->loadByDir($value, $isReload);
} }
if (is_file($value)) { if (is_file($value)) {
if (!$this->checkFile($value, $isReload)) { if ($this->checkFile($value, $isReload)) {
continue; $this->timerReload();
break;
} }
$this->timerReload();
break;
} }
} }
Timer::after(2000, [$this, 'tick']);
} }
/** /**
* @param $value * @param $value
* @param $isReload * @param $isReload
@@ -190,13 +192,9 @@ class ServerInotify extends Process
*/ */
public function timerReload() public function timerReload()
{ {
if ($this->isReloading) {
return;
}
$this->isReloading = true; $this->isReloading = true;
$this->trigger_reload(); $this->trigger_reload();
$this->int = -1; $this->int = -1;
$this->md5Map = [];
$this->loadByDir(APP_PATH . 'app'); $this->loadByDir(APP_PATH . 'app');
$this->loadByDir(APP_PATH . 'routes'); $this->loadByDir(APP_PATH . 'routes');
@@ -205,7 +203,7 @@ class ServerInotify extends Process
$this->isReloading = FALSE; $this->isReloading = FALSE;
$this->isReloadingOut = FALSE; $this->isReloadingOut = FALSE;
Timer::after(2000, [$this, 'tick']); $this->tick();
} }
/** /**