Fixed bug that update config everytime.

This commit is contained in:
李铭昕 2020-03-16 15:30:03 +08:00
parent d866567016
commit 8f7891b9d7
3 changed files with 22 additions and 9 deletions

View File

@ -67,12 +67,14 @@ class BootProcessListener implements ListenerInterface
Coroutine::create(function () {
$interval = $this->config->get('aliyun_acm.interval', 5);
retry(INF, function () use ($interval) {
$prevConfig = [];
while (true) {
sleep($interval);
$config = $this->client->pull();
if ($config !== $this->config) {
if ($config !== $prevConfig) {
$this->updateConfig($config);
}
$prevConfig = $config;
}
}, $interval * 1000);
});

View File

@ -83,12 +83,14 @@ class BootProcessListener implements ListenerInterface
Coroutine::create(function () {
$interval = $this->config->get('config_etcd.interval', 5);
retry(INF, function () use ($interval) {
$prevConfig = [];
while (true) {
sleep($interval);
$config = $this->client->pull();
if ($config !== $this->config) {
if ($config !== $prevConfig) {
$this->updateConfig($config);
}
$prevConfig = $config;
}
}, $interval * 1000);
});

View File

@ -62,18 +62,27 @@ class BootProcessListener implements ListenerInterface
Coroutine::create(function () {
$interval = $this->config->get('zookeeper.interval', 5);
retry(INF, function () use ($interval) {
$prevConfig = [];
while (true) {
$config = $this->client->pull();
if ($config !== $this->config) {
foreach ($config ?? [] as $key => $value) {
$this->config->set($key, $value);
$this->logger->debug(sprintf('Config [%s] is updated', $key));
}
}
sleep($interval);
$config = $this->client->pull();
if ($config !== $prevConfig) {
$this->updateConfig($config);
}
$prevConfig = $config;
}
}, $interval * 1000);
});
}
}
protected function updateConfig(array $config)
{
foreach ($config as $key => $value) {
if (is_string($key)) {
$this->config->set($key, $value);
$this->logger->debug(sprintf('Config [%s] is updated', $key));
}
}
}
}