beanstalkd_view 0.1.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -53,7 +53,7 @@ bundle exec beanstalkd_view
53
53
 
54
54
  Screenshot
55
55
  ------------------------
56
- ![Screenshot](http://s15.postimage.org/burvb1tjv/i_OS_Simulator_Screen_shot_Apr_5_2012_3_31_51_PM.png)
56
+ ![Screenshot](http://s16.postimage.org/4mdum0x79/i_OS_Simulator_Screen_shot_Apr_24_2012_10_29_33.png)
57
57
 
58
58
  License
59
59
  ------------------------
@@ -102,7 +102,7 @@ $(document).ready(function() {
102
102
 
103
103
  function create_new_job_buttons() {
104
104
  var job_info_buttons = "";
105
- job_info_buttons += "<a id=\"confirm_add_job_btn\" href=\"javascript:false\" class=\"btn\">Add Job</a>";
105
+ job_info_buttons += "<a id=\"confirm_add_job_btn\" href=\"#\" class=\"btn\">Add Job</a>";
106
106
  return job_info_buttons;
107
107
  }
108
108
 
@@ -1,9 +1,43 @@
1
+ # Overiding the standard beanstalk-client Pool to ignore NotFoundErrors.
2
+ # In this application, those errors should only occur when using multiple beanstalkd instances,
3
+ # when one instance does not have a tube, and others do.
4
+ module Beanstalk
5
+ class Pool
6
+ def call_wrap(c, *args, &block)
7
+ self.last_conn = c
8
+ c.send(*args, &block)
9
+ rescue NotFoundError => ex
10
+ puts "Ignoring NotFoundError: #{ex.class}: #{ex}"
11
+ nil
12
+ rescue UnexpectedResponse => ex
13
+ raise ex
14
+ rescue EOFError, Errno::ECONNRESET, Errno::EPIPE => ex
15
+ self.remove(c)
16
+ raise ex
17
+ end
18
+
19
+ def on_tube(tube, &block)
20
+ response = nil
21
+ connection_size = open_connections.size
22
+ # Retry if the desired tube is not found
23
+ # Randomly picking over double the connection size, should eventually find it...
24
+ # but a better algorithm would be nicer at some point...
25
+ # Note, that with just 1 beanstalkd instance, this code should always return on the first send
26
+ for i in 1..(connection_size*2)
27
+ response = send_to_rand_conn(:on_tube, tube, &block)
28
+ break if not response.nil?
29
+ end
30
+ response
31
+ end
32
+ end
33
+ end
34
+
1
35
  module BeanstalkdView
2
36
 
3
37
  class Server < Sinatra::Base
4
38
  include BeanstalkdView::BeanstalkdUtils
5
39
  enable :sessions
6
-
40
+
7
41
  get "/" do
8
42
  begin
9
43
  @tubes = beanstalk.list_tubes
@@ -40,7 +74,8 @@ module BeanstalkdView
40
74
 
41
75
  get "/tube/:tube" do
42
76
  begin
43
- @stats = beanstalk.stats_tube(params[:tube])
77
+ @tube = params[:tube]
78
+ @stats = beanstalk.stats_tube(@tube)
44
79
  @message = session[:message]
45
80
  session[:message] = nil
46
81
  erb :tube_stats
@@ -54,15 +89,11 @@ module BeanstalkdView
54
89
  begin
55
90
  response = nil
56
91
  beanstalk.on_tube(params[:tube]) do |conn|
57
- puts "On Tube #{conn.inspect} #{params[:type]}"
58
92
  if (params[:type]) == "ready"
59
- puts "Peaking Ready"
60
93
  response = conn.peek_ready()
61
94
  elsif (params[:type]) == "delayed"
62
- puts "Peaking Delayed"
63
95
  response = conn.peek_delayed()
64
96
  else
65
- puts "Peeking Buried"
66
97
  response = conn.peek_buried()
67
98
  end
68
99
  end
@@ -137,18 +168,21 @@ module BeanstalkdView
137
168
  send_file file
138
169
  end
139
170
 
171
+ private
172
+
173
+ # Return the stats data in a format for the Bluff JS UI Charts
140
174
  def get_chart_data_hash(tubes)
141
175
  chart_data = Hash.new
142
176
  chart_data["total_jobs_data"] = Hash.new
143
177
  chart_data["buried_jobs_data"] = Hash.new
144
178
  chart_data["total_jobs_data"]["items"] = Array.new
145
- chart_data["buried_jobs_data"]["items"] = Array.new
146
- tubes.keys.each do |key|
147
- tubes[key].each do |tube|
179
+ chart_data["buried_jobs_data"]["items"] = Array.new
180
+ tube_set(tubes).each do |tube|
181
+ begin
148
182
  stats = beanstalk.stats_tube(tube)
149
183
  #total_jobs
150
184
  total_jobs = stats['total-jobs']
151
- if total_jobs > 0
185
+ if total_jobs > 0
152
186
  total_datum = Hash.new
153
187
  total_datum["label"] = tube
154
188
  total_datum["data"] = total_jobs
@@ -162,10 +196,23 @@ module BeanstalkdView
162
196
  buried_datum["data"] = buried_jobs
163
197
  chart_data["buried_jobs_data"]["items"] << buried_datum
164
198
  end
199
+ rescue Beanstalk::NotFoundError
200
+ puts "Ignoring Beanstalk::NotFoundError for #{tube}"
165
201
  end
166
202
  end
167
203
  chart_data
168
204
  end
169
-
205
+
206
+ # Return a Set of tube names
207
+ def tube_set(tubes)
208
+ tube_set = Set.new
209
+ tubes.keys.each do |key|
210
+ tubes[key].each do |tube|
211
+ tube_set.add(tube)
212
+ end
213
+ end
214
+ tube_set
215
+ end
216
+
170
217
  end
171
218
  end
@@ -1,3 +1,3 @@
1
1
  module BeanstalkdView
2
- VERSION = "0.1.9"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -327,11 +327,11 @@ $(document).ready(function(){
327
327
  }
328
328
 
329
329
  <% if @total_jobs_data %>
330
- var total_jobs_data = <%= @total_jobs_data.to_json.html_safe %>
330
+ var total_jobs_data = <%= @total_jobs_data.to_json %>
331
331
  draw_pie_chart('total_jobs_chart', total_jobs_data);
332
332
  <% end %>
333
333
  <% if @buried_jobs_data %>
334
- var buried_jobs_data = <%= @buried_jobs_data.to_json.html_safe %>
334
+ var buried_jobs_data = <%= @buried_jobs_data.to_json %>
335
335
  draw_pie_chart('buried_jobs_chart', buried_jobs_data);
336
336
  $("#buried_jobs_container").css('visibility', 'visible');
337
337
  <% end %>
@@ -1,6 +1,6 @@
1
1
  <div class="row">
2
2
  <div class="span6">
3
- <h1><%= @stats["name"] %></h1>
3
+ <h1><%= @tube %></h1>
4
4
 
5
5
  <table class="table">
6
6
  <thead>
@@ -88,7 +88,7 @@
88
88
  <div class="span6">
89
89
  <h3>Pause Tube</h3>
90
90
  <form class="well form-inline" name="pause_form" action="<%= url('/pause') %>" method="POST">
91
- <input id="form_tube_name" type="hidden" name="tube" value="<%= @stats["name"] %>">
91
+ <input id="form_tube_name" type="hidden" name="tube" value="<%= @tube %>">
92
92
  <input id="form_url_base" type="hidden" name="url_base" value="<%= url('/') %>">
93
93
  <input type="text" class="span3" placeholder="Number of seconds to wait" name="delay">
94
94
  <button type="submit" class="btn">Pause</button>
@@ -96,7 +96,7 @@
96
96
 
97
97
  <h3>Kick Tube</h3>
98
98
  <form class="well form-inline" name="kick_form" action="<%= url('/kick') %>" method="POST">
99
- <input type="hidden" name="tube" value="<%= @stats["name"] %>">
99
+ <input type="hidden" name="tube" value="<%= @tube %>">
100
100
  <input type="text" class="span3" placeholder="Number of jobs" name="bound">
101
101
  <button type="submit" class="btn">Kick</button>
102
102
  </form>
@@ -2,13 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe BeanstalkdView::Server, :type => :request do
4
4
 
5
- before :all do
6
- ENV['BEANSTALK_URL'] = 'beanstalk://localhost/'
7
- Capybara.app = BeanstalkdView::Server.new
8
- end
9
-
10
5
  describe "with beanstalkd daemon running", :requires_beanstalkd => true do
11
6
  before :all do
7
+ ENV['BEANSTALK_URL'] = 'beanstalk://localhost/'
8
+ Capybara.app = BeanstalkdView::Server.new
9
+
12
10
  # Make sure beanstalkd is running
13
11
  if `pgrep beanstalkd` == ""
14
12
  raise "PRECONDITION NOT MET: beanstalkd not running"
@@ -27,10 +25,87 @@ describe BeanstalkdView::Server, :type => :request do
27
25
  body.should have_content "Beanstalkd View"
28
26
  body.should have_content "Statistics"
29
27
  end
28
+
29
+ it "show be able to add a job on the overview page", :js => true do
30
+ visit '/'
31
+ form = find('#add_job_form')
32
+ form.fill_in 'form_tube_name', :with => 'test.tube'
33
+ form.fill_in 'form_job_body', :with => '{"id": 1, "name": "Bob"}'
34
+ form.click_link('Add Job')
35
+ body.should have_content "Add new job?"
36
+ click_link "confirm_add_job_btn"
37
+ body.should have_content "Added job "
38
+ end
39
+
40
+ it "show be able to click on the test.tube link (created by the last test)", :js => true do
41
+ visit '/'
42
+ click_link('test.tube')
43
+ body.should have_content "test.tube"
44
+ end
45
+
46
+ =begin
47
+ # Current beanstalk-client lib doesn't support pause_tube action
48
+ it "show be able to pause a tube", :js => true do
49
+ visit '/tube/test.tube'
50
+ fill_in 'delay', :with => 1
51
+ click_button "Pause"
52
+ body.should have_content "Paused test.tube"
53
+ end
54
+ =end
55
+
56
+ it "show be able to kick a tube", :js => true do
57
+ visit '/tube/test.tube'
58
+ fill_in 'bound', :with => 1
59
+ click_button "Kick"
60
+ body.should have_content "Kicked test.tube"
61
+ end
62
+
63
+ it "show be able to peek_ready a tube", :js => true do
64
+ visit '/tube/test.tube'
65
+ click_button "peek_ready_btn"
66
+ body.should have_content "Job id:"
67
+ end
68
+ end
69
+
70
+ describe "with two beanstalkd daemons running", :requires_two_beanstalkd => true do
71
+ before :all do
72
+ ENV['BEANSTALK_URL'] = 'beanstalk://localhost:12300/,beanstalk://localhost:12400/'
73
+ Capybara.app = BeanstalkdView::Server.new
74
+
75
+ # Make sure beanstalkd is running
76
+ if `pgrep beanstalkd` == ""
77
+ raise "PRECONDITION NOT MET: beanstalkd not running"
78
+ end
79
+ end
80
+
81
+ it "should show the overview at: /" do
82
+ visit '/'
83
+ body.should have_content "Beanstalkd View"
84
+ body.should have_content "Statistics"
85
+ body.should have_content "Tubes"
86
+ end
87
+
88
+ it "show be able to add a job on the overview page, and view its stats", :js => true do
89
+ visit '/'
90
+ form = find('#add_job_form')
91
+ form.fill_in 'form_tube_name', :with => 'test.tube'
92
+ form.fill_in 'form_job_body', :with => '{"id": 1, "name": "Bob"}'
93
+ form.click_link('Add Job')
94
+ body.should have_content "Add new job?"
95
+ click_link "confirm_add_job_btn"
96
+ body.should have_content "Added job "
97
+
98
+ visit '/'
99
+ click_link('test.tube')
100
+ body.should have_content "test.tube"
101
+ end
30
102
  end
31
103
 
32
104
  describe "with out beanstalkd daemon running" do
33
105
  before :all do
106
+ ENV['BEANSTALK_URL'] = 'beanstalk://localhost/'
107
+ Capybara.app = BeanstalkdView::Server.new
108
+
34
109
  # Make sure beanstalkd is NOT running
35
110
  if `pgrep beanstalkd` != ""
36
111
  raise "PRECONDITION NOT MET: beanstalkd running"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beanstalkd_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-16 00:00:00.000000000 Z
12
+ date: 2012-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &2156722560 !ruby/object:Gem::Requirement
16
+ requirement: &2152680400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156722560
24
+ version_requirements: *2152680400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: beanstalk-client
27
- requirement: &2156722060 !ruby/object:Gem::Requirement
27
+ requirement: &2152679160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.1.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156722060
35
+ version_requirements: *2152679160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vegas
38
- requirement: &2156721580 !ruby/object:Gem::Requirement
38
+ requirement: &2152677540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.1.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156721580
46
+ version_requirements: *2152677540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
- requirement: &2156721180 !ruby/object:Gem::Requirement
49
+ requirement: &2152677140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2156721180
57
+ version_requirements: *2152677140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &2156720600 !ruby/object:Gem::Requirement
60
+ requirement: &2152676540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2156720600
68
+ version_requirements: *2152676540
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
- requirement: &2156720060 !ruby/object:Gem::Requirement
71
+ requirement: &2152675740 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2156720060
79
+ version_requirements: *2152675740
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2156719460 !ruby/object:Gem::Requirement
82
+ requirement: &2152674980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2156719460
90
+ version_requirements: *2152674980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: capybara
93
- requirement: &2156718720 !ruby/object:Gem::Requirement
93
+ requirement: &2152674400 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2156718720
101
+ version_requirements: *2152674400
102
102
  description: A Sinatra app to view/manage beanstalkd queues that can be embedded in
103
103
  a Rails app similar to what's available in Resque
104
104
  email: dennis.kuczynski@gmail.com