Skip to content

Commit

Permalink
Adding a hubot script for Messaging queues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Umang Chouhan committed Feb 5, 2014
1 parent c2d5b6f commit 0b89496
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions mq.coffee
Original file line number Original file line Diff line number Diff line change
@@ -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.