Permalink
Browse files

Adding a hubot script for Messaging queues.

  • Loading branch information...
1 parent c2d5b6f commit 0b89496aefab47981b891b1fc7c69070b45afeea @uchouhan uchouhan committed Feb 5, 2014
Showing with 40 additions and 0 deletions.
  1. +40 −0 mq.coffee
View
@@ -0,0 +1,40 @@
+# Description:
+# Shows the status of Messaging's resque queues
+#
+# Dependencies:
+# None
+#
+# Configuration:
+# RESQUE_WEB_URL
+#
+# Commands:
+# hubot resque - Lists the queues with pending jobs
+#
+# Author:
+# Umang Chouhan - OptimisCorp.
+
+module.exports = (robot) ->
+ url = 'https://messaging.optimispt.com/resque'
+ robot.respond /mq/i, (msg) ->
+ msg.http(url + '/stats.txt')
+ .get() (err, res, body) ->
+ msg.send format_stats parse_stats body
+
+parse_stats = (stats) ->
+ details = {}
+ handle_line = (line) ->
+ [key,val] = line.split '='
+ [group,name] = key.split '.'
+ (details[group]||={})[name.replace('+','')] = val
+ handle_line response for response in stats.split '\n'
+ details
+
+
+format_stats = (stats) ->
+ heading = "#{stats['resque']['pending']} pending jobs. #{stats['resque']['working']} of #{stats['resque']['workers']} workers active."
+ queues = ([count,name] for name,count of stats['queues'] when count isnt '0').sort (a,b) -> b[0] - a[0]
+ justify = (str, size) ->
+ Array(size - str.length + 1).join(' ') + str
+ width = Math.max.apply null, (q[1].length for q in queues)
+ queue_list = ("#{justify(q[1], width + 1)} : #{q[0]}" for q in queues).join '\n'
+ return heading + '\n' + queue_list

0 comments on commit 0b89496

Please sign in to comment.