From a56af856b89b9e18030c02298f12e16387cabff4 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 30 Aug 2012 15:52:47 -0400 Subject: [PATCH 1/3] CC-4322: Prevent pypo-notify from hanging if server becomes unresponsive -fixed --- python_apps/api_clients/api_client.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 7fb2de631..983b59281 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -71,7 +71,7 @@ class AirtimeApiClient(): self.logger.error('Error loading config file: %s', e) sys.exit(1) - def get_response_from_server(self, url): + def get_response_from_server(self, url, attempts=-1): logger = self.logger successful_response = False @@ -93,6 +93,14 @@ class AirtimeApiClient(): else: logger.debug(url) + #If the user passed in a positive attempts number then that means + #attempts will roll over 0 and we stop. If attempts was initially negative, + #then we have unlimited attempts + if attempts > 0: + attempts = attempts - 1 + if attempts == 0: + successful_response = True + if not successful_response: logger.error("Error connecting to server, waiting 5 seconds and trying again.") time.sleep(5) @@ -240,7 +248,7 @@ class AirtimeApiClient(): url = url.replace("%%api_key%%", self.config["api_key"]) - self.get_response_from_server(url) + self.get_response_from_server(url, attempts=5) except Exception, e: logger.error("Exception: %s", str(e)) @@ -259,7 +267,7 @@ class AirtimeApiClient(): logger.debug(url) url = url.replace("%%api_key%%", self.config["api_key"]) - response = self.get_response_from_server(url) + response = self.get_response_from_server(url, attempts = 5) response = json.loads(response) logger.info("API-Status %s", response['status']) logger.info("API-Message %s", response['message']) @@ -591,7 +599,7 @@ class AirtimeApiClient(): url = url.replace("%%stream_id%%", stream_id) url = url.replace("%%boot_time%%", time) - self.get_response_from_server(url) + self.get_response_from_server(url, attempts = 5) except Exception, e: logger.error("Exception: %s", e) @@ -604,7 +612,7 @@ class AirtimeApiClient(): url = url.replace("%%sourcename%%", sourcename) url = url.replace("%%status%%", status) - self.get_response_from_server(url) + self.get_response_from_server(url, attempts = 5) except Exception, e: logger.error("Exception: %s", e) @@ -725,6 +733,6 @@ class AirtimeApiClient(): self.logger.debug(url) request = urllib2.Request(url, data) - self.logger.info(self.get_response_from_server(request)) + self.logger.info(self.get_response_from_server(request, attempts = 5)) except Exception, e: self.logger.error("Exception: %s", e) From 796885594f1d98a8d4318c9f74b6145fe9f07a9a Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 30 Aug 2012 15:56:34 -0400 Subject: [PATCH 2/3] CC-4322: Prevent pypo-notify from hanging if server becomes unresponsive -fixed --- python_apps/pypo/liquidsoap_scripts/notify.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python_apps/pypo/liquidsoap_scripts/notify.sh b/python_apps/pypo/liquidsoap_scripts/notify.sh index fa69cd1e8..23ea71c37 100755 --- a/python_apps/pypo/liquidsoap_scripts/notify.sh +++ b/python_apps/pypo/liquidsoap_scripts/notify.sh @@ -10,4 +10,5 @@ SCRIPT=`readlink -f $0` # Absolute path this script is in SCRIPTPATH=`dirname $SCRIPT` -cd ${SCRIPTPATH}/../ && python pyponotify.py "$@" +cd ${SCRIPTPATH}/../ +timeout 15 python pyponotify.py "$@" From f9dca673767611459d9f265ca45817a4eb1f8775 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 30 Aug 2012 15:58:05 -0400 Subject: [PATCH 3/3] CC-4322: Prevent pypo-notify from hanging if server becomes unresponsive -up timeout to 45 sec --- python_apps/pypo/liquidsoap_scripts/notify.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/pypo/liquidsoap_scripts/notify.sh b/python_apps/pypo/liquidsoap_scripts/notify.sh index 23ea71c37..fccb768fa 100755 --- a/python_apps/pypo/liquidsoap_scripts/notify.sh +++ b/python_apps/pypo/liquidsoap_scripts/notify.sh @@ -11,4 +11,4 @@ SCRIPT=`readlink -f $0` SCRIPTPATH=`dirname $SCRIPT` cd ${SCRIPTPATH}/../ -timeout 15 python pyponotify.py "$@" +timeout 45 python pyponotify.py "$@"