diff --git a/src/App/Service/IPListService.php b/src/App/Service/IPListService.php index e7ae100..357d4d5 100644 --- a/src/App/Service/IPListService.php +++ b/src/App/Service/IPListService.php @@ -8,6 +8,8 @@ use OpenCCK\Infrastructure\API\App; use Exception; use Monolog\Logger; +use Revolt\EventLoop; +use function Amp\delay; class IPListService { private static IPListService $_instance; @@ -34,6 +36,13 @@ class IPListService { $this->loadConfig($name, json_decode(file_get_contents($dir . $file))); } } + + EventLoop::queue(function () { + foreach ($this->sites as $siteEntity) { + $siteEntity->reload(); + delay(1); + } + }); } /** diff --git a/src/Domain/Entity/Site.php b/src/Domain/Entity/Site.php index b38cfbd..3cf4be8 100644 --- a/src/Domain/Entity/Site.php +++ b/src/Domain/Entity/Site.php @@ -40,13 +40,15 @@ final class Site { public object $external = new stdClass() ) { $this->dnsHelper = new DNSHelper($dns); - EventLoop::delay(0, $this->reload(...)); } /** * @return void */ - private function reload(): void { + public function reload(): void { + $startTime = time(); + App::getLogger()->notice('Reloading for ' . $this->name, ['started']); + $ip4 = []; $ip6 = []; foreach (array_chunk($this->domains, \OpenCCK\getEnv('SYS_DNS_RESOLVE_CHUNK_SIZE') ?? 10) as $chunk) { @@ -67,7 +69,7 @@ final class Site { $this->ip6 = SiteFactory::normalize(array_merge($this->ip6, $ip6), true); $this->saveConfig(); - App::getLogger()->debug('Reloaded for ' . $this->name); + App::getLogger()->notice('Reloaded for ' . $this->name, ['finished', time() - $startTime]); EventLoop::delay($this->timeout, function () { $this->reloadExternal();