Add no_retry arg in auth method
- make initial authentication without retry
to avoid infinite loop blocking __init__()
to return and therefore logs from appearing
- catch any exception appearing during auth()
execution
Change-Id: Ibe9d872f3621e1bd37d35732990e0b91eb4589f6
Related-PROD: PRODX-24306
diff --git a/sf_notifier/salesforce/client.py b/sf_notifier/salesforce/client.py
index f86c2f0..d3979e8 100644
--- a/sf_notifier/salesforce/client.py
+++ b/sf_notifier/salesforce/client.py
@@ -93,7 +93,7 @@
self.environment = self.config.pop('environment_id')
self.sf = None
self.session = Session()
- self.auth()
+ self.auth(no_retry=True)
@staticmethod
def _hash_func(name):
@@ -131,7 +131,7 @@
try:
config.update({'session': self.session})
self.sf = Salesforce(**config)
- except sf_exceptions.SalesforceAuthenticationFailed as ex:
+ except Exception as ex:
logger.error('Salesforce authentication failure: {}.'.format(ex))
self.metrics['sf_auth_ok'].set(0)
return False
@@ -172,6 +172,7 @@
# only one worker at a time can check session_file
auth_success = False
+ logger.info('Attempting to lock session file.')
with open(SESSION_FILE, 'r+') as session_file:
with flocked(session_file):
logger.info('Successfully locked session file for refresh.')
@@ -199,8 +200,12 @@
return auth_success
- def auth(self):
+ def auth(self, no_retry=False):
auth_ok = self._acquire_session()
+
+ if no_retry:
+ return
+
while auth_ok is False:
auth_ok = self._acquire_session()