This commit is contained in:
2021-11-05 00:23:31 +08:00
parent c73fe2d609
commit 825539c792
2 changed files with 9 additions and 10 deletions
@@ -56,7 +56,7 @@ class FileChangeCustomProcess extends Command
public function execute(InputInterface $input, OutputInterface $output): int
{
// TODO: Implement onHandler() method.
// set_error_handler([$this, 'onErrorHandler']);
set_error_handler([$this, 'onErrorHandler']);
$this->dirs = Config::get('inotify', [APP_PATH . 'app']);
if (!extension_loaded('inotify')) {
@@ -64,10 +64,9 @@ class FileChangeCustomProcess extends Command
} else {
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
}
$this->trigger_reload(0);
Coroutine::create(function () use ($driver) {
$driver->start(Coroutine::getCid());
});
$driver->start();
return 0;
}
@@ -92,7 +91,7 @@ class FileChangeCustomProcess extends Command
*
* @throws Exception
*/
public function trigger_reload($cid)
public function trigger_reload()
{
Kiri::getDi()->get(Logger::class)->warning('change reload');
+3 -3
View File
@@ -31,15 +31,15 @@ class Inotify
/**
* @throws Exception
*/
public function start($cid)
public function start()
{
$this->cid = $cid;
$this->inotify = inotify_init();
$this->events = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE;
foreach ($this->dirs as $dir) {
if (!is_dir($dir)) continue;
$this->watch($dir);
}
$this->process->trigger_reload();
Event::add($this->inotify, [$this, 'check']);
Event::wait();
}
@@ -84,7 +84,7 @@ class Inotify
public function reload()
{
$this->process->isReloading = true;
$this->process->trigger_reload($this->cid);
$this->process->trigger_reload();
$this->clearWatch();
foreach ($this->dirs as $root) {