diff --git a/config.py b/config.py index c18a1fd69..a35c3113e 100644 --- a/config.py +++ b/config.py @@ -291,6 +291,9 @@ class DefaultConfig(object): # How often the Garbage Collection worker runs. GARBAGE_COLLECTION_FREQUENCY = 30 # seconds + # How long notifications will try to send before timing out. + NOTIFICATION_SEND_TIMEOUT = 10 + # Security scanner FEATURE_SECURITY_SCANNER = False FEATURE_SECURITY_NOTIFICATIONS = False diff --git a/endpoints/notificationmethod.py b/endpoints/notificationmethod.py index 18844715f..b315be9b6 100644 --- a/endpoints/notificationmethod.py +++ b/endpoints/notificationmethod.py @@ -14,6 +14,8 @@ from workers.queueworker import JobException logger = logging.getLogger(__name__) +METHOD_TIMEOUT = app.config.get('NOTIFICATION_SEND_TIMEOUT', 10) # Seconds + class InvalidNotificationMethodException(Exception): pass @@ -190,7 +192,8 @@ class WebhookMethod(NotificationMethod): headers = {'Content-type': 'application/json'} try: - resp = requests.post(url, data=json.dumps(payload), headers=headers, cert=SSLClientCert) + resp = requests.post(url, data=json.dumps(payload), headers=headers, cert=SSLClientCert, + timeout=METHOD_TIMEOUT) if resp.status_code/100 != 2: error_message = '%s response for webhook to url: %s' % (resp.status_code, url) logger.error(error_message) @@ -241,7 +244,7 @@ class FlowdockMethod(NotificationMethod): } try: - resp = requests.post(url, data=json.dumps(payload), headers=headers) + resp = requests.post(url, data=json.dumps(payload), headers=headers, timeout=METHOD_TIMEOUT) if resp.status_code/100 != 2: error_message = '%s response for flowdock to url: %s' % (resp.status_code, url) logger.error(error_message) @@ -302,7 +305,7 @@ class HipchatMethod(NotificationMethod): } try: - resp = requests.post(url, data=json.dumps(payload), headers=headers) + resp = requests.post(url, data=json.dumps(payload), headers=headers, timeout=METHOD_TIMEOUT) if resp.status_code/100 != 2: error_message = '%s response for hipchat to url: %s' % (resp.status_code, url) logger.error(error_message) @@ -420,7 +423,7 @@ class SlackMethod(NotificationMethod): } try: - resp = requests.post(url, data=json.dumps(payload), headers=headers) + resp = requests.post(url, data=json.dumps(payload), headers=headers, timeout=METHOD_TIMEOUT) if resp.status_code/100 != 2: error_message = '%s response for Slack to url: %s' % (resp.status_code, url) logger.error(error_message)