Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions augur/tasks/github/util/github_api_key_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import random

from typing import List
from sqlalchemy.orm import Session

Check warning on line 6 in augur/tasks/github/util/github_api_key_handler.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0611: Unused Session imported from sqlalchemy.orm (unused-import) Raw Output: augur/tasks/github/util/github_api_key_handler.py:6:0: W0611: Unused Session imported from sqlalchemy.orm (unused-import)

from augur.tasks.util.redis_list import RedisList
from augur.application.db.lib import get_value, get_worker_oauth_keys
from sqlalchemy import func

Check warning on line 10 in augur/tasks/github/util/github_api_key_handler.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0611: Unused func imported from sqlalchemy (unused-import) Raw Output: augur/tasks/github/util/github_api_key_handler.py:10:0: W0611: Unused func imported from sqlalchemy (unused-import)

RATE_LIMIT_URL = "https://api.github.com/rate_limit"

Expand Down Expand Up @@ -92,13 +92,15 @@
if redis_keys:
return redis_keys

# Initialize keys to empty list to prevent NameError if all retries fail
keys = []
attempts = 0
while attempts < 3:

try:
keys = self.get_api_keys_from_database()
break
except:
except Exception as e:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be more effective using except* to capture nested exceptions and decode them all; though I think @ABrain7710 will have the final say on whether or not this is a good idea.

self.logger.warning(f"Failed to get API keys from database (attempt {attempts + 1}/3): {e}")
time.sleep(5)
attempts += 1

Expand Down Expand Up @@ -132,16 +134,6 @@
raise NoValidKeysError("No valid github api keys found in the config or worker oauth table")


# shuffling the keys so not all processes get the same keys in the same order
valid_now = valid_keys
#try:
#self.logger.info(f'valid keys before shuffle: {valid_keys}')
#valid_keys = random.sample(valid_keys, len(valid_keys))
#self.logger.info(f'valid keys AFTER shuffle: {valid_keys}')
#except Exception as e:
# self.logger.debug(f'{e}')
# valid_keys = valid_now
# pass

return valid_keys

Expand Down