basic pulse-observing start
authorMike Shaver <shaver@mozilla.org>
Wed, 03 Nov 2010 02:48:20 +0000
changeset 9 9f0ca4539fdd7496de99b7ec1c4d1deafc70c01a
parent 8 f25733a37297dc20819651788435276f39fad214
child 10 14d8fb886c0236b669a2c6307b4e8d64a317bf72
push id10
push usershaver@mozilla.com
push dateWed, 03 Nov 2010 02:50:39 +0000
basic pulse-observing start
server/pulse.js
new file mode 100644
--- /dev/null
+++ b/server/pulse.js
@@ -0,0 +1,67 @@
+var
+    amqp = require("amqp"),
+    util = require("util"),
+    fs = require("fs");
+
+var config = {
+    mozpulse: {
+	host: "pulse.mozilla.org",
+	login: "public",
+	password: "public"
+    }
+};
+
+var connection = amqp.createConnection(config.mozpulse);
+
+connection.addListener('error', function(e) { util.puts("ERROR:" + e); });
+
+var sample = { };
+
+function onBugzillaMessage(message)
+{
+    var bug = message.payload.bug;
+    var prefix = process.argv[2] || "";
+
+    switch (message._routingKey) {
+      case "bug.new":
+        addNewBug(message.payload.bug.id, message.payload.bug.summary);
+        if (!sample.newBug) {
+            sample.newBug = message;
+            fs.writeFileSync(prefix + "new-bug.json", JSON.stringify(message));
+            console.log("captured new bug");
+        }
+        break;
+      case "bug.changed.summary":
+        updateSummary(message.payload.bug.id, message.payload.bug.status, message.payload.before, message.payload.after);
+        if (!sample.changedBug) {
+            sample.changedBug = message;
+            fs.writeFileSync(prefix + "changed-bug.json", JSON.stringify(message));
+            console.log("captured summary-changed bug");
+        }
+        break;
+      case "bug.changed.status":
+        maybeRemoveClosedBug(message.payload.bug.id, message.payload.before, message.payload.after,
+                             message.payload.bug.summary);
+        if (!sample.closedBug) {
+            sample.closedBug = message;
+            fs.writeFileSync(prefix + "closed-bug.json", JSON.stringify(message));
+            console.log("captured status-changed bug");
+        }
+        break;
+      default:
+        console.log("unknown routing key " + message._routingKey);
+        break;
+    }
+}
+
+connection.addListener('ready',
+                       function () {
+                           var q = connection.queue("shaver@mozilla.com|bugzilla-index",
+                                                    function (count) { util.puts(count + " messages in queue"); });
+
+                           q.bind("org.mozilla.exchange.bugzilla", "bug.changed.summary");
+                           q.bind("org.mozilla.exchange.bugzilla", "bug.changed.status");
+                           q.bind("org.mozilla.exchange.bugzilla", "bug.new");
+                           
+                           q.subscribe(onBugzillaMessage);
+                       });