← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~julian-edwards/txlongpoll/add-oops into lp:txlongpoll

 

Julian Edwards has proposed merging lp:~julian-edwards/txlongpoll/add-oops into lp:txlongpoll.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~julian-edwards/txlongpoll/add-oops/+merge/76741

Add oops handling to the txlongpoll server.
-- 
https://code.launchpad.net/~julian-edwards/txlongpoll/add-oops/+merge/76741
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/txlongpoll/add-oops into lp:txlongpoll.
=== modified file 'setup.py'
--- setup.py	2011-09-20 16:50:43 +0000
+++ setup.py	2011-09-23 15:09:23 +0000
@@ -15,6 +15,8 @@
     zip_safe=False,
     description='Long polling HTTP frontend for AMQP',
     install_requires=[
+        'oops_datedir_repo',
+        'oops_twisted',
         'Twisted',
         'txamqp',
         'zope.interface',

=== modified file 'twisted/plugins/longpoll.py'
--- twisted/plugins/longpoll.py	2011-07-12 07:09:20 +0000
+++ twisted/plugins/longpoll.py	2011-09-23 15:09:23 +0000
@@ -5,11 +5,20 @@
 
 from zope.interface import implements
 
+from oops_datedir_repo import DateDirRepo
+from oops_twisted import (
+    Config as oops_config,
+    defer_publisher,
+    OOPSObserver,
+    )
 from twisted.application.internet import TCPServer, TCPClient
 from twisted.application.service import IServiceMaker, MultiService
 from twisted.plugin import IPlugin
 from twisted.python import log, usage
-from twisted.python.log import ILogObserver, FileLogObserver
+from twisted.python.log import (
+    addObserver,
+    FileLogObserver
+    )
 from twisted.python.logfile import LogFile
 from twisted.web.server import Site
 
@@ -17,7 +26,7 @@
 from txlongpoll.frontend import QueueManager, FrontEndAjax
 
 
-def setUpLogFile(application, filename):
+def getRotatableLogFileObserver(filename):
     """Setup a L{LogFile} for the given application."""
     logfile = LogFile.fromFullPath(
         filename, rotateLength=None, defaultMode=0644)
@@ -26,19 +35,38 @@
         logfile.reopen()
 
     signal.signal(signal.SIGUSR1, signal_handler)
-    application.setComponent(ILogObserver, FileLogObserver(logfile).emit)
+    return FileLogObserver(logfile)
+
+
+def setUpOopsHandler(options):
+    """Add OOPS handling based on the passed command line options."""
+    config = oops_config()
+
+    # Add the oops publisher that writes files in the configured place
+    # if the command line option was set.
+    if options["oops-dir"]:
+        repo = DateDirRepo(options["oops-dir"], options["oops-prefix"])
+        config.publishers.append(defer_publisher(repo))
+
+    # Add the log file observers. The second observer is to put OOPSes
+    # in the log too.
+    logfile = getRotatableLogFileObserver(options["logfile"])
+    observer = OOPSObserver(config, logfile.emit)
+    addObserver(observer.emit)
 
 
 class Options(usage.Options):
     optParameters = [
-        ["logfile", "l", None, "Optional logfile name."],
+        ["logfile", "l", "txlongpoll.log", "Logfile name."],
         ["brokerport", "p", 5672, "Broker port"],
         ["brokerhost", "h", '127.0.0.1', "Broker host"],
         ["brokeruser", "u", None, "Broker user"],
         ["brokerpassword", "a", None, "Broker password"],
-        ["brokervhost", "v", '127.0.0.1', "Broker vhost"],
+        ["brokervhost", "v", '/', "Broker vhost"],
         ["frontendport", "f", None, "Frontend port"],
         ["prefix", "x", 'XXX', "Queue prefix"],
+        ["oops-dir", "r", None, "Where to write OOPS reports"],
+        ["oops-prefix", "o", "LONGPOLL", "String prefix for OOPS IDs"],
         ]
 
     def postOptions(self):
@@ -62,9 +90,7 @@
 
     def makeService(self, options):
         """Construct a TCPServer and TCPClient. """
-        # See Twisted bug 638.
-        #if options["logfile"]:
-        #    setUpLogFile(application, options["logfile"])
+        setUpOopsHandler(options)
 
         broker_port = options["brokerport"]
         broker_host = options["brokerhost"]


Follow ups