mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-03 04:08:01 +08:00
Fixed bug that update config everytime.
This commit is contained in:
parent
d866567016
commit
8f7891b9d7
@ -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);
|
||||
});
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user