Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry connecting to GitLab API on error #337

Merged
merged 1 commit into from
Jan 2, 2024
Merged
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
26 changes: 25 additions & 1 deletion did/plugins/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""

import distutils.util
from time import sleep

import dateutil
import requests
Expand All @@ -37,6 +38,10 @@
GITLAB_SSL_VERIFY = True
GITLAB_API = 4

# Retry fetching
GITLAB_ATTEMPTS = 5
GITLAB_INTERVAL = 5

# Identifier padding
PADDING = 3

Expand All @@ -61,7 +66,26 @@ def __init__(self, url, token, ssl_verify=GITLAB_SSL_VERIFY):
self.project_issues = {}

def _get_gitlab_api_raw(self, url):
return requests.get(url, headers=self.headers, verify=self.ssl_verify)
log.debug("Connecting to GitLab API at '%s'.", url)
retries = 0
while True:
try:
api_raw = requests.get(
url, headers=self.headers, verify=self.ssl_verify)
return api_raw
except requests.exceptions.ConnectionError as connection_error:
retries += 1
if retries > GITLAB_ATTEMPTS:
raise ReportError(
f"Unable to connect to '{url}'. Error: {connection_error}"
) from connection_error
log.debug(
"Retrying connection to '%s' in %s seconds due to %s.",
url,
GITLAB_INTERVAL,
connection_error
)
sleep(GITLAB_INTERVAL)

def _get_gitlab_api(self, endpoint):
url = '{0}/api/v{1}/{2}'.format(self.url, GITLAB_API, endpoint)
Expand Down
Loading