Skip to content

Commit d7872d3

Browse files
authored
Add confd.watch option, default as true. (#826)
* Add `confd.watch` option, default as `true`. * 将 'interval' 配置项修改为从环境变量 'CONFD_INTERVAL' 获取值,默认为 1 --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
1 parent c65f33e commit d7872d3

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

publish/confd.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@
6363

6464
'env_path' => BASE_PATH . '/.env',
6565

66-
'interval' => 1,
66+
// Watch on boot
67+
'watch' => (bool) env('CONFD_WATCH', true),
6768

69+
// Watch keys
6870
'watches' => [
6971
'DB_HOST',
7072
],
73+
74+
// Watch interval
75+
'interval' => (int) env('CONFD_INTERVAL', 1),
7176
];

src/Listener/WatchOnBootListener.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use FriendsOfHyperf\Confd\Confd;
1515
use FriendsOfHyperf\Confd\Traits\Logger;
16+
use Hyperf\Contract\ConfigInterface;
1617
use Hyperf\Event\Contract\ListenerInterface;
1718
use Hyperf\Framework\Event\MainWorkerStart;
1819
use Hyperf\Server\Event\MainCoroutineServerStart;
@@ -22,8 +23,10 @@ class WatchOnBootListener implements ListenerInterface
2223
{
2324
use Logger;
2425

25-
public function __construct(private ContainerInterface $container)
26-
{
26+
public function __construct(
27+
private ContainerInterface $container,
28+
private ConfigInterface $config
29+
) {
2730
$this->resolveLogger();
2831
}
2932

@@ -40,6 +43,10 @@ public function listen(): array
4043
*/
4144
public function process(object $event): void
4245
{
46+
if (! $this->config->get('confd.watch', true)) {
47+
return;
48+
}
49+
4350
$this->container->get(Confd::class)->watch();
4451
$this->logger?->debug('[confd] Start watching.');
4552
}

0 commit comments

Comments
 (0)