From 938db9ed777dde647f6c2291e2a877fa7895d6a7 Mon Sep 17 00:00:00 2001 From: hafsanaeem-2 Date: Tue, 27 Dec 2022 22:59:32 +0000 Subject: [PATCH 1/2] retry after exception --- connections/github.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/connections/github.py b/connections/github.py index 5bf6f2a0..afd1f661 100644 --- a/connections/github.py +++ b/connections/github.py @@ -10,6 +10,8 @@ # license: GPLv2 # import datetime +import time + from tools import config, logging from github import Github, GithubIntegration @@ -28,15 +30,23 @@ def get_token(): with open(private_key_path, 'r') as private_key_file: private_key = private_key_file.read() - # If the config keys are not set, get_access_token will raise a NotImplementedError - # Returning NoneType token will stop the connection in get_instance - try: - github_integration = GithubIntegration(app_id, private_key) - # Note that installation access tokens last only for 1 hour, you will need to regenerate them after they expire. - _token = github_integration.get_access_token(installation_id) - except NotImplementedError as err: - logging.error(err) - _token = None + tries = 3 + for i in range(tries): + # If the config keys are not set, get_access_token will raise a NotImplementedError + # Returning NoneType token will stop the connection in get_instance + try: + github_integration = GithubIntegration(app_id, private_key) + # Note that installation access tokens last only for 1 hour, + # you will need to regenerate them after they expire. + _token = github_integration.get_access_token(installation_id) + except NotImplementedError as err: + if i < tries - 1: + time.sleep(0.8) + continue + else: + logging.error(err) + _token = None + break return _token From 63773f172d20d4d46a1d6f4dc7d2b1a1bad47104 Mon Sep 17 00:00:00 2001 From: hafsanaeem-2 Date: Sun, 1 Jan 2023 23:38:51 +0000 Subject: [PATCH 2/2] change the wait time --- connections/github.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/connections/github.py b/connections/github.py index afd1f661..d8eb3f66 100644 --- a/connections/github.py +++ b/connections/github.py @@ -39,14 +39,16 @@ def get_token(): # Note that installation access tokens last only for 1 hour, # you will need to regenerate them after they expire. _token = github_integration.get_access_token(installation_id) + break except NotImplementedError as err: if i < tries - 1: - time.sleep(0.8) + n = 0.8 + t = n*(i+1) + time.sleep(t) continue else: logging.error(err) _token = None - break return _token