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,15 +81,19 @@ def main(): ...@@ -80,15 +81,19 @@ 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')}
try:
notification = httplib.HTTPConnection(notification_url.hostname, notification = httplib.HTTPConnection(notification_url.hostname,
notification_port) notification_port)
notification.request('POST', notification_url.path, body, headers) notification.request('POST', notification_url.path, body, headers)
response = notification.getresponse() 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 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
if some_notification_failed: if some_notification_failed:
sys.exit(1) sys.exit(1)
......
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