Skip to content

Commit

Permalink
Add timeout to requests calls
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeebot[bot] authored Apr 12, 2024
1 parent 9c4b2b0 commit f96f6d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions backend-container/src/apimappings/PushFeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
# Function to handle the subscription and be_logger.infoing of data@log_and_catch_exceptions
def subscribe_to_feed(feed_url, params):
while True:
with requests.get(feed_url, params=params, allow_redirects=False, stream=True) as r:
with requests.get(feed_url, params=params, allow_redirects=False, stream=True, timeout=60) as r:
if r.status_code == 200:
redirect_url = r.headers['Location']
be_logger.info(f"Listening for data on {feed_url}")
with requests.get(redirect_url, stream=True) as stream:
with requests.get(redirect_url, stream=True, timeout=60) as stream:
for line in stream.iter_lines():
if line:
decoded_line = line.decode('utf-8')
Expand Down Expand Up @@ -62,4 +62,4 @@ def start_subscriptions(api_key):

# Keep the main thread running to keep the subscription threads alive
for thread in threads:
thread.join()
thread.join()
4 changes: 2 additions & 2 deletions backend-container/src/apimappings/current_season_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def fetch_and_save_all_seasons_schedule():
for season_type in ['REG', 'PST']:
url = SEASONS_API_URL.format(year=year, season_type=season_type, API_KEY=API_KEY)
be_logger.info(f"Requesting URL at {datetime.now()}: {fetch_and_save_all_seasons_schedule}")
response = requests.get(url)
response = requests.get(url, timeout=60)
be_logger.info(f"Response status code for {fetch_and_save_all_seasons_schedule}: {response.status_code}")

if response.status_code != 200:
Expand Down Expand Up @@ -74,7 +74,7 @@ def fetch_and_save_weekly_schedule():
url = WEEKLY_SCHEDULE_API_URL.format(
season_year=season_year, season_type=season_type, week_number=week_number, API_KEY=API_KEY)
be_logger.info(f"{datetime.now()} Requesting URL: {url}")
response = requests.get(url)
response = requests.get(url, timeout=60)
be_logger.info(f"Response status code: {response.status_code}")
if response.status_code != 200:
return f"GetCurrentSeasonScheduleError for {season_year} {season_type} {week_number}: {response.status_code}"
Expand Down

0 comments on commit f96f6d8

Please sign in to comment.