feat(config): watch runtime configuration changes (#5026)

This commit is contained in:
chengyongru
2026-07-22 13:08:39 +08:00
committed by GitHub
parent 7bf7469d90
commit 3748f664b2
11 changed files with 190 additions and 7 deletions
+23
View File
@@ -0,0 +1,23 @@
"""System-level notification for config file changes."""
from __future__ import annotations
from collections.abc import Callable
from pathlib import Path
from watchfiles import Change, awatch
async def watch_config_file(config_path: Path, on_change: Callable[[], None]) -> None:
"""Notify ``on_change`` after the configured file changes."""
target = config_path.resolve(strict=False)
def is_config_file(_change: Change, changed_path: str) -> bool:
return Path(changed_path).resolve(strict=False) == target
async for _changes in awatch(
target.parent,
watch_filter=is_config_file,
recursive=False,
):
on_change()