Skip to content

Commit

Permalink
Retry on HTTP 500
Browse files Browse the repository at this point in the history
  • Loading branch information
reconman committed Feb 18, 2024
1 parent afe4353 commit 9d45d4f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion plexanisync/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def update_score(self, media_id, score_raw: int):
self.__send_graphql_request(op)

def __send_graphql_request(self, operation):
retries = 10

while True:
data = self.endpoint(operation)
if "errors" in data:
Expand All @@ -199,11 +201,14 @@ def __send_graphql_request(self, operation):
logger.warning(f"Rate limit hit, waiting for {wait_time}s")
time.sleep(wait_time + 1)

elif retries > 0:
retries = retries - 1
time.sleep(1)
else:
raise data["exception"]
else:
# wait a bit to not overload AniList API
time.sleep(1)
time.sleep(0.2)
return data

def __mediaitem_to_object(self, media_item) -> AnilistSeries:
Expand Down

0 comments on commit 9d45d4f

Please sign in to comment.