fix delete old state

This commit is contained in:
Yuriy Yuriev
2026-05-29 22:06:34 +07:00
parent b02b7518cf
commit e438f09693
4 changed files with 52 additions and 14 deletions
+11 -2
View File
@@ -165,6 +165,9 @@ class BrowserService:
if not settings.STICKY_PROXY_HOST:
return VisitResult(url=url, success=False, error="No proxy configured")
# Максимальное время одной попытки: запуск браузера + загрузка страницы + чтение + буфер
attempt_timeout = reading_time + 150
for attempt in range(3):
try:
proxy_config, proxy_url, proxy_info = _make_sticky_proxy_config()
@@ -185,8 +188,11 @@ class BrowserService:
if proxy_locale:
camoufox_kwargs["locale"] = proxy_locale
async with AsyncCamoufox(**camoufox_kwargs) as browser:
result = await self._browse_page(browser, url, proxy_info, reading_time)
async def _run_browser():
async with AsyncCamoufox(**camoufox_kwargs) as browser:
return await self._browse_page(browser, url, proxy_info, reading_time)
result = await asyncio.wait_for(_run_browser(), timeout=attempt_timeout)
is_proxy_dead = result.error and any(
k in result.error for k in ("502", "Bad Gateway", "NS_ERROR_PROXY")
@@ -204,6 +210,9 @@ class BrowserService:
self._proxy_fail_streak = 0
return result
except asyncio.TimeoutError:
logger.warning(f"Visit attempt {attempt + 1} timed out after {attempt_timeout}s, retrying")
except (ValueError, InvalidIP, InvalidProxy) as e:
logger.warning(f"Visit attempt {attempt + 1} proxy error, retrying: {e}")