feat: do dns reboot for sites sequentially

This commit is contained in:
Rekryt
2024-09-03 21:20:44 +03:00
parent da43b05497
commit c56dc4dd05
2 changed files with 14 additions and 3 deletions

View File

@@ -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);
}
});
}
/**

View File

@@ -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();