fix monitoring
This commit is contained in:
@@ -361,55 +361,4 @@ class BrowserService:
|
||||
logger.error(f"Cleanup error: {e}")
|
||||
|
||||
async def visit_page_from_twitch(self, url: str, channel: str, reading_time: int = None) -> VisitResult:
|
||||
if reading_time is None:
|
||||
reading_time = random.randint(settings.DEFAULT_MIN_READING, settings.DEFAULT_MAX_READING)
|
||||
|
||||
proxy = None
|
||||
|
||||
for attempt in range(2):
|
||||
try:
|
||||
if self.proxy_manager.has_proxies():
|
||||
proxy = await self.proxy_manager.acquire_proxy(timeout=90)
|
||||
|
||||
if proxy and proxy.proxy_type in [ProxyType.SOCKS5, ProxyType.SOCKS4]:
|
||||
proxy_config = await self.socks5_pool.get_proxy_config(proxy)
|
||||
elif proxy:
|
||||
proxy_config = proxy.proxy_config
|
||||
else:
|
||||
proxy_config = None
|
||||
|
||||
browser_kwargs = {
|
||||
"headless": True,
|
||||
"geoip": True,
|
||||
"humanize": True,
|
||||
"exclude_addons": [DefaultAddons.UBO],
|
||||
}
|
||||
|
||||
if proxy_config:
|
||||
browser_kwargs["proxy"] = proxy_config
|
||||
|
||||
async with AsyncCamoufox(**browser_kwargs) as browser:
|
||||
result = await self._browse_page(
|
||||
browser,
|
||||
url,
|
||||
proxy.id if proxy else "direct",
|
||||
reading_time
|
||||
)
|
||||
|
||||
if proxy:
|
||||
await self.proxy_manager.release_proxy(proxy, result.success)
|
||||
|
||||
if result.success:
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Attempt {attempt + 1} failed: {e}")
|
||||
if proxy:
|
||||
await self.proxy_manager.release_proxy(proxy, success=False)
|
||||
await self.socks5_pool.release(proxy)
|
||||
proxy = None
|
||||
|
||||
if attempt < 1:
|
||||
await asyncio.sleep(2)
|
||||
|
||||
return VisitResult(url=url, success=False, error="All attempts failed")
|
||||
return await self.visit_page(url, reading_time)
|
||||
|
||||
Reference in New Issue
Block a user