mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-12 16:39:35 +03:00
feat: do dns reboot for sites sequentially
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user