← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~lifeless/python-oops-tools/amqp into lp:python-oops-tools

 

Robert Collins has proposed merging lp:~lifeless/python-oops-tools/amqp into lp:python-oops-tools.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~lifeless/python-oops-tools/amqp/+merge/79749

Update the amqp support to be a little easier to use and more robust. Also working properly. (I've had a dev environment doing just-in-time reporting of OOPSes! \o/).
-- 
https://code.launchpad.net/~lifeless/python-oops-tools/amqp/+merge/79749
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/python-oops-tools/amqp into lp:python-oops-tools.
=== modified file 'src/oopstools/NEWS.txt'
--- src/oopstools/NEWS.txt	2011-10-18 04:15:08 +0000
+++ src/oopstools/NEWS.txt	2011-10-18 23:10:28 +0000
@@ -9,6 +9,12 @@
 
 * Bumped oops-amqp rev to 0.0.2 for bugfixes. (Robert Collins)
 
+* amqp2disk now creates a fanout exchange if --bind-to is supplied.
+  (Robert Collins)
+
+* amqp2disk -v will print the received OOPS ids on the console, for
+  entertainment and delight. (Robert Collins)
+
 0.6
 ===
 

=== modified file 'src/oopstools/scripts/amqp2disk.py'
--- src/oopstools/scripts/amqp2disk.py	2011-10-18 04:15:08 +0000
+++ src/oopstools/scripts/amqp2disk.py	2011-10-18 23:10:28 +0000
@@ -55,9 +55,12 @@
         The AMQP environment should be setup in advance with a persistent queue
         bound to your exchange : using transient queues would allow OOPSes to
         be lost if the amqp2disk process were to be shutdown for a non-trivial
-        duration. The --bind-to option will cause the queue to be created and
-        bound to the given exchange. This is only needed the first time as it
-        is created persistently.
+        duration. The --bind-to option will cause the queue (and exchange if
+        necessary) to be created and bound together. This is only needed the
+        first time as it is created persistently. Running it when the exchange
+        already exists (to setup a second worker, or because you manually
+        created it with a different setup) is fine. The default setup is a
+        fanout exchange.
         """)
     description = "Load OOPS reports into oops-tools from AMQP."
     parser = optparse.OptionParser(
@@ -70,6 +73,8 @@
     parser.add_option('--queue', help="AMQP queue name.")
     parser.add_option(
         '--bind-to', help="AMQP exchange to bind to (only needed once).")
+    parser.add_option("-v", "--verbose", action="store_true",
+        help="Print more information about what is going on.")
     options, args = parser.parse_args(argv[1:])
     def needed(optname):
         if getattr(options, optname, None) is None:
@@ -88,6 +93,8 @@
         try:
             channel = connection.channel()
             try:
+                channel.exchange_declare(
+                    options.bind_to, type="fanout", durable=True, auto_delete=False)
                 channel.queue_declare(
                     options.queue, durable=True, auto_delete=False)
                 channel.queue_bind(options.queue, options.bind_to)
@@ -96,6 +103,10 @@
         finally:
             connection.close()
     config = make_amqp_config(options.output)
+    if options.verbose:
+        def print_oops(report):
+            print ("Received %s" % report['id'])
+        config.publishers.append(print_oops)
     receiver = oops_amqp.Receiver(config, factory, options.queue)
     try:
         receiver.run_forever()