Skip to content

Commit

Permalink
handle proxy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Nov 6, 2023
1 parent ec43a98 commit 5664dce
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from time import time

import requests
from aiohttp import ClientSession
from aiohttp import ClientHttpProxyError, ClientResponseError, ClientSession
from aiokafka import AIOKafkaConsumer, AIOKafkaProducer
from pydantic import BaseModel

Expand Down Expand Up @@ -113,6 +113,17 @@ async def scrape_data(
player, hiscore = await scraper.lookup_hiscores(player, session)
player: Player
hiscore: dict

except (ClientResponseError, ClientHttpProxyError) as error:
session = ClientSession(timeout=app_config.SESSION_TIMEOUT)
error_type = type(error)
sleep_time = 35
logger.error(
f"{name} - {error_type.__name__}: {str(error)} - {error_count=} - {player.name=}"
)
await player_send_queue.put(item=player.dict())
await asyncio.sleep(sleep_time)
continue
except Exception as error:
error_type = type(error)
sleep_time = max(error_count * 2, 5)
Expand Down

0 comments on commit 5664dce

Please sign in to comment.