Bug 1231560: Log and ack messages that we can't handle r=nthomas
authorChris AtLee <catlee@mozilla.com>
Fri, 11 Dec 2015 14:32:17 -0500
changeset 297 9a9039732de95f26acf757ae7fdfcf9feb2960dc
parent 296 0037c36dbfb92f02714faf5b2de3275aab144131
child 298 1d22c7eafd43e04a940f85ae4382f4bcccba5810
push id242
push usercatlee@mozilla.com
push dateFri, 11 Dec 2015 19:32:33 +0000
reviewersnthomas
bugs1231560
Bug 1231560: Log and ack messages that we can't handle r=nthomas
buildapi/scripts/selfserve-agent.py
setup.py
--- a/buildapi/scripts/selfserve-agent.py
+++ b/buildapi/scripts/selfserve-agent.py
@@ -5,22 +5,25 @@ Gets any messages and executes them."""
 import logging as log
 import time
 import urllib
 import urllib2
 from urlparse import urlparse
 import subprocess
 import uuid
 import re
+import socket
 
 from sqlalchemy import text
 from sqlalchemy.exc import TimeoutError
 
 from buildapi.lib import json
 
+HOSTNAME = socket.gethostname()
+
 
 class NoRedirects(urllib2.HTTPErrorProcessor):
     "Helper class that eats HTTP 302 redirects so we don't follow redirects"
     def http_response(self, request, response):
         if response.code == 302:
             return response
         return urllib2.HTTPErrorProcessor.http_response(self, request, response)
 
@@ -250,18 +253,24 @@ class BuildAPIAgent:
             msg = {'body': retval}
             msg['request_id'] = message_data['body']['request_id']
             self.publisher.ack_msg(msg)
             message.ack()
         except TimeoutError:
             log.exception("TimeoutError accessing the DB pool")
             raise
         except:
-            log.exception("Error processing message")
-            raise
+            # Send a failure message
+            log.exception("Error processing message; logging failure and acking")
+            msg = {'body': {"errors": True, "msg":
+                            "there was an error processing your request; please "
+                            "check logs on %s" % HOSTNAME}}
+            msg['request_id'] = message_data['body']['request_id']
+            self.publisher.ack_msg(msg)
+            message.ack()
 
     def do_reprioritize(self, message_data, message):
         who = message_data['who']
         brid = message_data['body']['brid']
         priority = message_data['body']['priority']
         log.info("reprioritizing request by %s of request %s to priority %s",
                  who, brid, priority)
 
--- a/setup.py
+++ b/setup.py
@@ -2,17 +2,17 @@ try:
     from setuptools import setup, find_packages
 except ImportError:
     from ez_setup import use_setuptools
     use_setuptools()
     from setuptools import setup, find_packages
 
 setup(
     name='buildapi',
-    version='0.3.20',
+    version='0.3.21',
     description='',
     author='',
     author_email='',
     url='',
     install_requires=[
         "SQLAlchemy<0.9.0",
         "kombu",
         "pytz",