mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 03:30:48 +08:00
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import Any, Callable, Protocol
|
|
|
|
from .gmail_watcher import GmailWatcherResult, start_gmail_watcher
|
|
|
|
|
|
class GmailWatcherLog(Protocol):
|
|
def info(self, msg: str) -> None: ...
|
|
def warn(self, msg: str) -> None: ...
|
|
def error(self, msg: str) -> None: ...
|
|
|
|
|
|
def _is_truthy_env(value: str | None) -> bool:
|
|
return str(value or "").strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
def _skip_gmail_watcher_env() -> bool:
|
|
for key in ("OCLAW_SKIP_GMAIL_WATCHER", "OPENCLAW_SKIP_GMAIL_WATCHER"):
|
|
if _is_truthy_env(os.getenv(key)):
|
|
return True
|
|
return False
|
|
|
|
|
|
def start_gmail_watcher_with_logs(
|
|
*,
|
|
cfg: dict[str, Any] | None,
|
|
log: GmailWatcherLog,
|
|
on_skipped: Callable[[], None] | None = None,
|
|
starter: Callable[[dict[str, Any] | None], GmailWatcherResult] = start_gmail_watcher,
|
|
) -> None:
|
|
"""Skip entirely when ``OCLAW_SKIP_GMAIL_WATCHER`` or ``OPENCLAW_SKIP_GMAIL_WATCHER`` is truthy."""
|
|
if _skip_gmail_watcher_env():
|
|
if on_skipped:
|
|
on_skipped()
|
|
return
|
|
|
|
try:
|
|
res = starter(cfg)
|
|
if bool(res.started):
|
|
log.info("gmail watcher started")
|
|
return
|
|
reason = str(res.reason or "").strip()
|
|
if reason and reason not in {
|
|
"hooks not enabled",
|
|
"no gmail account configured",
|
|
"gmail watcher runtime not implemented (Python)",
|
|
}:
|
|
log.warn(f"gmail watcher not started: {reason}")
|
|
except Exception as exc:
|
|
log.error(f"gmail watcher failed to start: {exc}")
|
|
|