Skip to content

Commit

Permalink
Implemented a retry with 60sec pause on HTTP 429
Browse files Browse the repository at this point in the history
See #1
  • Loading branch information
keul committed May 1, 2022
1 parent fee5e50 commit 9fd8f50
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions haunts/calendars.py
Original file line number Diff line number Diff line change
@@ -1,3 1,4 @@
import time
import datetime
import click
from dateutil import parser
Expand Down Expand Up @@ -90,15 91,30 @@ def create_event(config_dir, calendar, date, summary, details, length, from_time
"date": (end datetime.timedelta(days=1)).isoformat()[:10],
}

event = {
event_body = {
"summary": summary,
"description": details,
"start": startParams,
"end": endParams,
}

LOGGER.debug(calendar, date, summary, details, length, event, from_time)
event = service.events().insert(calendarId=calendar, body=event).execute()
def execute_creation():
LOGGER.debug(calendar, date, summary, details, length, event_body, from_time)
event = service.events().insert(calendarId=calendar, body=event_body).execute()
return event

try:
event = execute_creation()
except HttpError as err:
if err.status_code == 429:
click.echo("Too many requests")
click.echo(err.error_details)
click.echo("haunts will now pause for a while ⏲…")
time.sleep(60)
click.echo("Retrying…")
event = execute_creation()
else:
raise
LOGGER.debug(event.items())
if duration:
click.echo(
Expand Down

0 comments on commit 9fd8f50

Please sign in to comment.