Skip to content

Commit

Permalink
Retry twice when inserting member into Google Group (#7)
Browse files Browse the repository at this point in the history
Docs:
https://googleapis.github.io/google-api-python-client/docs/epy/googleapiclient.http.HttpRequest-class.html#execute

We consistently run into SSLEOFError after a period of idling. When
manually retrying, the request seems to go through. This PR uses the
`num_retries` argument to automatically retry on request failure.
  • Loading branch information
ben-z authored Aug 20, 2024
1 parent c4797ba commit 922b42e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/google_admin_sdk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def __init__(self, logger=logging.getLogger(__name__)):
def get_group(self, group_key: str):
return self.service.groups().get(groupKey=group_key).execute()

def insert_member(self, group_key: str, email: str):
def insert_member(self, group_key: str, email: str, num_retries: int = 2):
try:
self.service.members().insert(groupKey=group_key, body={"email": email}).execute()
self.service.members().insert(groupKey=group_key, body={"email": email}).execute(num_retries=num_retries)
except HttpError as e:
if e.resp.status == 409:
self.logger.warning(f"Member {email} already exists in group {group_key}. Ignoring.")
Expand Down

0 comments on commit 922b42e

Please sign in to comment.