Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better status UI, json support, add sinatra dev dep

  • Loading branch information...
commit a657af6bca1b3f10d4a392efc36fad90fe10975e 1 parent 4541266
@mperham authored
View
1  girl_friday.gemspec
@@ -16,4 +16,5 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
+ s.add_development_dependency 'sinatra', '~> 1.0'
end
View
19 lib/girl_friday/server.rb
@@ -20,11 +20,30 @@ class Server < Sinatra::Base
helpers do
include Rack::Utils
alias_method :h, :escape_html
+
+ def dashboard(stats)
+ if stats[:busy] == stats[:pool_size] && stats[:backlog] < stats[:pool_size]
+ ['#ffc', 'Busy']
+ elsif stats[:busy] == stats[:pool_size] && stats[:backlog] >= stats[:pool_size]
+ ['#fcc', 'Busy and Backlogged']
+ else
+ ['white', 'OK']
+ end
+ end
end
get '/' do
+ redirect "#{request.env['REQUEST_URI']}/status"
+ end
+
+ get '/status' do
@status = GirlFriday.status
erb :index
end
+
+ get '/status.json' do
+ content_type :json
+ GirlFriday.status.to_json
+ end
end
end
View
2  lib/girl_friday/work_queue.rb
@@ -7,7 +7,7 @@ class WorkQueue
attr_reader :name
def initialize(name, options={}, &block)
- @name = name
+ @name = name.to_s
@size = options[:size] || 5
@processor = block
@error_handler = (options[:error_handler] || ErrorHandler.default).new
View
1  rails_app/Gemfile
@@ -2,6 +2,7 @@ source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'girl_friday', :path => '..'
+gem 'sinatra'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
59 server/views/index.erb
@@ -8,39 +8,44 @@
h1 { font-size: 2em; padding-bottom: 5px;}
h2 { font-size: 1.5em; padding-bottom: 5px;}
h3 { font-size: 1.3em; padding-bottom: 5px;}
- html, body { height: 100%; }
- body { margin: 0; padding: 0; font-size: 14px; font-family: sans-serif; background-color: #ddd; }
- #menu { float: left; width: 20%; background-color: #fdd;}
- #main { float: right; background-color: #dfd; width: 75%;}
- #content { padding: 10px; width: 100%; }
- #header { background-color: #ddf; padding: 10px; }
- .queue { padding-bottom: 20px; }
+ body { margin: 0 auto; width: 1000px; padding: 0; font-size: 14px; font-family: sans-serif; background-color: white; }
+ #header { padding: 10px 0;}
+ #queues { border-collapse: collapse; width: 100%; border: 1px solid black; }
+ #queues TD { border: 1px solid black; padding: 5px; }
+ #queues TH { padding: 5px; text-align: left; background: #444; color: #ddf; border: 1px solid black; }
</style>
<div id="header">
<h1>girl_friday</h1>
</div>
- <div id="content">
- <div id="menu">
- <h2>Queues</h2>
- <ul>
- <% @status.keys.each do |name| %>
- <li><a href="#<%= h name %>"><%= h name %></a>
- <% end %>
- </ul>
- </div>
-
- <div id="main">
- <% @status.each_pair do |name, stats| %>
- <div class="queue">
- <a name="<%= h name %>">
- <h3><%= h name %></h3>
- <p><%= stats.inspect %></p>
- </div>
- <% end %>
- </div>
-
+ <div id="main">
+ <table id="queues">
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Size</th>
+ <th>Busy</th>
+ <th>Backlog</th>
+ <th>Status</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @status.keys.sort.each do |name|
+ stats = @status[name]
+ (bg, note) = dashboard(stats)
+ %>
+ <tr style="background-color: <%= bg %>">
+ <td><%= h name %></td>
+ <td><%= stats[:pool_size] %></td>
+ <td><%= stats[:busy] %></td>
+ <td><%= stats[:backlog] %></td>
+ <td><%= note %></td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
</div>
+
</body>
</html>

0 comments on commit a657af6

Please sign in to comment.
Something went wrong with that request. Please try again.