Improve app initialization
- move SF auth to hook handlers
- client failure will not block whole app
- visible logs and metrics
Change-Id: Ib9c00539a9118127e239a17c5265db671bab0097
Related-PROD: PRODX-34058
diff --git a/sf_notifier/salesforce/client.py b/sf_notifier/salesforce/client.py
index eb39b77..590f04f 100644
--- a/sf_notifier/salesforce/client.py
+++ b/sf_notifier/salesforce/client.py
@@ -97,8 +97,6 @@
self.session.mount('http://', adapter)
self.session.mount('https://', adapter)
- self.auth(no_retry=True)
-
@staticmethod
def _init_metrics(prometheus_registry):
metrics = {
@@ -317,6 +315,10 @@
logger.warning('Alert ID: {} not found.'.format(alert_id))
def create_case(self, subject, body, labels):
+
+ if self.sf is None:
+ self.auth(no_retry=True)
+
alert_id = self._get_alert_id(labels)
error_code, case_id = self._create_case(subject, body,
@@ -334,6 +336,10 @@
return response
def close_case(self, labels):
+
+ if self.sf is None:
+ self.auth(no_retry=True)
+
alert_id = self._get_alert_id(labels)
case = self._get_case_by_alert_id(alert_id)