-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a hubot script for Messaging queues.
- Loading branch information
Umang Chouhan
committed
Feb 5, 2014
1 parent
c2d5b6f
commit 0b89496
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | 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 |