Commit ac4c75c6 authored by Marco Mariani's avatar Marco Mariani Committed by Cédric de Saint Martin

pubsub notifier: handle timeout and other connection errors

Signed-off-by: default avatarCédric de Saint Martin <cedric.dsm@tiolive.com>
parent 8b067d63
...@@ -9,6 +9,7 @@ import socket ...@@ -9,6 +9,7 @@ import socket
import subprocess import subprocess
import sys import sys
import time import time
import traceback
import urllib2 import urllib2
import urlparse import urlparse
import uuid import uuid
...@@ -80,14 +81,18 @@ def main(): ...@@ -80,14 +81,18 @@ def main():
notification_port = socket.getservbyname(notification_url.scheme) notification_port = socket.getservbyname(notification_url.scheme)
headers = {'Content-Type': feed.info().getheader('Content-Type')} headers = {'Content-Type': feed.info().getheader('Content-Type')}
notification = httplib.HTTPConnection(notification_url.hostname, try:
notification_port) notification = httplib.HTTPConnection(notification_url.hostname,
notification.request('POST', notification_url.path, body, headers) notification_port)
response = notification.getresponse() notification.request('POST', notification_url.path, body, headers)
response = notification.getresponse()
if not (200 <= response.status < 300): if not (200 <= response.status < 300):
sys.stderr.write("The remote server at %s didn't send a successful reponse.\n" % notif_url) sys.stderr.write("The remote server at %s didn't send a successful reponse.\n" % notif_url)
sys.stderr.write("Its response was %r\n" % response.reason) sys.stderr.write("Its response was %r\n" % response.reason)
some_notification_failed = True
except socket.error as exc:
sys.stderr.write("Connection with remote server at %s failed:\n" % notif_url)
sys.stderr.write(traceback.format_exc(exc))
some_notification_failed = True some_notification_failed = True
if some_notification_failed: if some_notification_failed:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment