Skip to content

Commit

Permalink
Wait extra 1 second for RS request
Browse files Browse the repository at this point in the history
Sometimes it still gets 429 if it waits the exact amount
  • Loading branch information
squaresmile committed Feb 10, 2024
1 parent 4a2295a commit 2c4d4ee
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/rayshift/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
NO_API_KEY = settings.rayshift_api_key.get_secret_value() == ""
QUEST_ENDPOINT = f"{settings.rayshift_api_url}/avalon-data-export/quests"
REGION_ENUM = {Region.JP: 1, Region.NA: 2}
DEFAULT_WAIT_SEC = 15


async def get_quest_response(
Expand All @@ -53,7 +54,7 @@ async def get_quest_response(
return QuestRayshiftResponse.parse_raw(r.content).response
elif r.status_code == httpx.codes.TOO_MANY_REQUESTS: # pragma: no cover
rate_limit = BaseRayshiftResponse.parse_raw(r.content)
wait_seconds = rate_limit.wait if rate_limit.wait else 60
wait_seconds = rate_limit.wait + 1 if rate_limit.wait else DEFAULT_WAIT_SEC
raise HTTPException(
status_code=r.status_code,
detail=f"Please wait {wait_seconds} seconds until you make the next quest request",
Expand Down Expand Up @@ -112,7 +113,7 @@ def get_multiple_quests(

r = client.get(f"{QUEST_ENDPOINT}/get", params=params)
if r.status_code == httpx.codes.TOO_MANY_REQUESTS: # pragma: no cover
sleep_time = r.json().get("wait", 10)
sleep_time = r.json().get("wait", DEFAULT_WAIT_SEC - 1) + 1
logger.info(f"Sleeping {sleep_time} seconds for RayShift API")
time.sleep(sleep_time)
r = client.get(f"{QUEST_ENDPOINT}/get", params=params)
Expand All @@ -121,6 +122,7 @@ def get_multiple_quests(
return QuestRayshiftResponse.parse_raw(r.content).response.questDetails
except ValidationError as e: # pragma: no cover
logger.exception(e)
logger.exception(r.text)
return {}


Expand Down

0 comments on commit 2c4d4ee

Please sign in to comment.