Silence OnlyOffice log spam when server is unreachable

- Cache docker bridge IP auto-detection (it cannot change at runtime),
  so the debug message is logged once instead of per preview.
- Log availability transitions only (unreachable/back), re-probing every
  30s via the existing TTL cache.
- Skip office conversion attempts entirely while OnlyOffice is known to
  be down; fail with a quiet 'onlyoffice error' 503.
This commit is contained in:
2026-08-11 21:32:16 +00:00
parent 8613d6c25e
commit f3b3b5efd9
+16 -2
View File
@@ -19,7 +19,7 @@ import subprocess
import threading
import urllib.error
import urllib.request
from functools import partial
from functools import lru_cache, partial
from http.server import SimpleHTTPRequestHandler
from pathlib import Path
from time import perf_counter
@@ -50,6 +50,7 @@ def _get_jwt_secret() -> str:
)
@lru_cache(maxsize=1)
def _get_callback_host() -> str:
"""Return the host IP that OnlyOffice (usually in Docker) can use to reach us."""
if host := os.environ.get("ONLYOFFICE_CALLBACK_HOST"):
@@ -199,7 +200,11 @@ OO_AVAILABILITY_CACHE_TTL = 30.0
async def is_available_cached() -> bool:
"""Return cached OnlyOffice availability, refreshed every 30 seconds."""
"""Return cached OnlyOffice availability, refreshed every 30 seconds.
State transitions are logged, so an unreachable server is reported once
instead of on every preview attempt.
"""
global _oo_available_cache
now = perf_counter()
if _oo_available_cache is not None:
@@ -207,6 +212,15 @@ async def is_available_cached() -> bool:
if now - timestamp < OO_AVAILABILITY_CACHE_TTL:
return result
result = await is_available_async()
if _oo_available_cache is None or _oo_available_cache[0] != result:
if result:
logger.info(
"OnlyOffice document server available at %s", _get_onlyoffice_url()
)
else:
logger.warning(
"OnlyOffice document server not reachable at %s", _get_onlyoffice_url()
)
_oo_available_cache = (result, now)
return result