Skip to content

Commit

Permalink
Add confd.watch option, default as true. (#826)
Browse files Browse the repository at this point in the history
* Add `confd.watch` option, default as `true`.

* 将 'interval' 配置项修改为从环境变量 'CONFD_INTERVAL' 获取值,默认为 1

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia authored Jan 14, 2025
1 parent c65f33e commit d7872d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion publish/confd.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@

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

'interval' => 1,
// Watch on boot
'watch' => (bool) env('CONFD_WATCH', true),

// Watch keys
'watches' => [
'DB_HOST',
],

// Watch interval
'interval' => (int) env('CONFD_INTERVAL', 1),
];
11 changes: 9 additions & 2 deletions src/Listener/WatchOnBootListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FriendsOfHyperf\Confd\Confd;
use FriendsOfHyperf\Confd\Traits\Logger;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\MainWorkerStart;
use Hyperf\Server\Event\MainCoroutineServerStart;
Expand All @@ -22,8 +23,10 @@ class WatchOnBootListener implements ListenerInterface
{
use Logger;

public function __construct(private ContainerInterface $container)
{
public function __construct(
private ContainerInterface $container,
private ConfigInterface $config
) {
$this->resolveLogger();
}

Expand All @@ -40,6 +43,10 @@ public function listen(): array
*/
public function process(object $event): void
{
if (! $this->config->get('confd.watch', true)) {
return;
}

$this->container->get(Confd::class)->watch();
$this->logger?->debug('[confd] Start watching.');
}
Expand Down

0 comments on commit d7872d3

Please sign in to comment.