Add wait 30s for auth error
- prevent auth requests flood (like with wrong credentials)
- makes easier log tracking
Change-Id: Id0e9c33a78d4623b08c6f5e24eb220d2c908f689
Related-bug: PROD-29246 (PROD:29246)
diff --git a/sf_notifier/salesforce/client.py b/sf_notifier/salesforce/client.py
index 95f324d..71ada18 100644
--- a/sf_notifier/salesforce/client.py
+++ b/sf_notifier/salesforce/client.py
@@ -65,7 +65,7 @@
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
yield
except IOError:
- logger.info('Waiting for session file 5 seconds...')
+ logger.info('Session file locked. Waiting 5 seconds...')
time.sleep(5)
finally:
fcntl.flock(fd, fcntl.LOCK_UN)
@@ -140,8 +140,8 @@
try:
config.update({'session': self.session})
self.sf = Salesforce(**config)
- except sf_exceptions.SalesforceAuthenticationFailed:
- logger.error('Salesforce authentication failure.')
+ except sf_exceptions.SalesforceAuthenticationFailed as ex:
+ logger.error('Salesforce authentication failure: {}.'.format(ex))
self.metrics['sf_auth_ok'].set(0)
return False
@@ -188,7 +188,7 @@
saved_session = self._load_session(session_file)
if self._refresh_ready(saved_session):
- logger.info('Attepmting to refresh session.')
+ logger.info('Attempting to refresh session.')
if self._auth(self.config):
auth_success = True
@@ -202,6 +202,10 @@
logger.info('Not refreshing. Reusing session.')
auth_success = self._reuse_session(saved_session)
+ if auth_success is False:
+ logger.warn('Waiting 30 seconds before next attempt...')
+ time.sleep(30)
+
return auth_success
def auth(self):