taolib.symphony.config.watcher#

Symphony 文件监视器。

基于 watchdog 监视 WORKFLOW.md 文件变更, 防抖后触发重新加载,验证失败时保持最后有效配置。

Attributes#

Classes#

_WorkflowEventHandler

WORKFLOW.md 文件变更事件处理器。

WorkflowWatcher

WORKFLOW.md 文件监视器。

Module Contents#

taolib.symphony.config.watcher.logger#
taolib.symphony.config.watcher._DEBOUNCE_MS = 500#
taolib.symphony.config.watcher.OnReloadSuccess#
taolib.symphony.config.watcher.OnReloadError#
class taolib.symphony.config.watcher._WorkflowEventHandler(workflow_path: pathlib.Path, on_reload_success: OnReloadSuccess | None, on_reload_error: OnReloadError | None)#

Bases: watchdog.events.FileSystemEventHandler

WORKFLOW.md 文件变更事件处理器。

实现防抖逻辑:收到变更事件后等待 _DEBOUNCE_MS, 如果期间没有新的变更事件则触发重新加载。

_workflow_path#
_on_reload_success#
_on_reload_error#
_last_event_time: float = 0.0#
_last_valid_config: taolib.symphony.config.schema.SymphonyConfig | None = None#
_debounce_seconds = 0.5#
on_modified(event: watchdog.events.FileModifiedEvent) None#

Called when a file or directory is modified.

参数:

event (DirModifiedEvent or FileModifiedEvent) -- Event representing file/directory modification.

_schedule_debounce() None#

防抖逻辑:在 _debounce_seconds 内无新事件时触发重新加载。

_do_reload() None#

执行重新加载。

property last_valid_config: taolib.symphony.config.schema.SymphonyConfig | None#

返回最后有效的配置。

class taolib.symphony.config.watcher.WorkflowWatcher(workflow_path: pathlib.Path, on_reload_success: OnReloadSuccess | None = None, on_reload_error: OnReloadError | None = None)#

WORKFLOW.md 文件监视器。

基于 watchdog 监视指定的工作流文件,变更时重新加载并验证配置。 验证失败则保持最后有效配置,不会使服务崩溃。

使用方式:

watcher = WorkflowWatcher(

workflow_path=Path("WORKFLOW.md"), on_reload_success=my_success_handler, on_reload_error=my_error_handler,

) watcher.start() # ... 服务运行 ... watcher.stop()

_workflow_path#
_handler#
_observer: watchdog.observers.Observer | None = None#
start() None#

启动文件监视。

stop() None#

停止文件监视。

property last_valid_config: taolib.symphony.config.schema.SymphonyConfig | None#

返回最后有效的配置。