beanstalkd_view 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/lib/beanstalkd_view/server.rb +39 -22
- data/lib/beanstalkd_view/version.rb +1 -1
- data/lib/beanstalkd_view/views/index.erb +13 -6
- data/lib/beanstalkd_view/views/layout.erb +13 -12
- data/lib/beanstalkd_view/views/tube_stats.erb +3 -3
- data/lib/beanstalkd_view.rb +1 -0
- data/spec/lib/beanstalkd_view/server_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +82 -20
data/README.md
CHANGED
@@ -23,6 +23,8 @@ Use the following environment variable to specify the location of the beanstalk
|
|
23
23
|
ENV['BEANSTALK_URL'] = 'beanstalk://localhost/'
|
24
24
|
```
|
25
25
|
|
26
|
+
(This can be a comma separated list.)
|
27
|
+
|
26
28
|
Embedding in a Rails app
|
27
29
|
------------------------
|
28
30
|
|
@@ -37,6 +39,17 @@ mount BeanstalkdView::Server, :at => "/beanstalkd"
|
|
37
39
|
You can then browse to your application path to view information about your beanstalkd tubes, i.e.
|
38
40
|
http://127.0.0.1:3000/beanstalkd
|
39
41
|
|
42
|
+
If you wish to authenticate the mounted app with Devise, it would look something like:
|
43
|
+
|
44
|
+
``` ruby
|
45
|
+
devise_for :admin_users, ActiveAdmin::Devise.config
|
46
|
+
|
47
|
+
match('/beanstalkd/admin/login' => redirect('/admin/login'))
|
48
|
+
authenticate :admin_user do
|
49
|
+
mount BeanstalkdView::Server, at: "/beanstalkd"
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
40
53
|
Running from the command line
|
41
54
|
------------------------
|
42
55
|
|
@@ -36,17 +36,26 @@ module BeanstalkdView
|
|
36
36
|
|
37
37
|
class Server < Sinatra::Base
|
38
38
|
include BeanstalkdView::BeanstalkdUtils
|
39
|
-
|
39
|
+
helpers Sinatra::Cookies
|
40
40
|
|
41
|
+
root = File.dirname(File.expand_path(__FILE__))
|
42
|
+
set :root, root
|
43
|
+
set :views, "#{root}/views"
|
44
|
+
if respond_to? :public_folder
|
45
|
+
set :public_folder, "#{root}/resources"
|
46
|
+
else
|
47
|
+
set :public, "#{root}/resources"
|
48
|
+
end
|
49
|
+
set :static, true
|
50
|
+
|
41
51
|
get "/" do
|
42
52
|
begin
|
43
53
|
@tubes = beanstalk.list_tubes
|
44
54
|
@stats = beanstalk.stats
|
45
|
-
|
55
|
+
@tube_set = tube_set(@tubes)
|
56
|
+
chart_data = get_chart_data_hash(@tube_set)
|
46
57
|
@total_jobs_data = chart_data["total_jobs_data"]
|
47
58
|
@buried_jobs_data = chart_data["buried_jobs_data"] if chart_data["buried_jobs_data"]["items"].size > 0
|
48
|
-
@message = session[:message]
|
49
|
-
session[:message] = nil
|
50
59
|
erb :index
|
51
60
|
rescue Beanstalk::NotConnected => @error
|
52
61
|
erb :error
|
@@ -61,10 +70,10 @@ module BeanstalkdView
|
|
61
70
|
response = conn.put([ params[:tube], body ].to_json, params[:priority].to_i, params[:delay].to_i, params[:ttr].to_i)
|
62
71
|
end
|
63
72
|
if response
|
64
|
-
|
73
|
+
cookies[:beanstalkd_view_notice] = "Added job #{response.inspect}"
|
65
74
|
redirect url("/")
|
66
75
|
else
|
67
|
-
|
76
|
+
cookies[:beanstalkd_view_notice] = "Error adding job"
|
68
77
|
redirect url("/")
|
69
78
|
end
|
70
79
|
rescue Beanstalk::NotConnected => @error
|
@@ -76,8 +85,6 @@ module BeanstalkdView
|
|
76
85
|
begin
|
77
86
|
@tube = params[:tube]
|
78
87
|
@stats = beanstalk.stats_tube(@tube)
|
79
|
-
@message = session[:message]
|
80
|
-
session[:message] = nil
|
81
88
|
erb :tube_stats
|
82
89
|
rescue Beanstalk::NotConnected => @error
|
83
90
|
erb :error
|
@@ -116,10 +123,10 @@ module BeanstalkdView
|
|
116
123
|
response = conn.delete(params[:job_id].to_i)
|
117
124
|
end
|
118
125
|
if response
|
119
|
-
|
126
|
+
cookies[:beanstalkd_view_notice] = "Deleted Job #{params[:job_id]}"
|
120
127
|
redirect url("/tube/#{params[:tube]}")
|
121
128
|
else
|
122
|
-
|
129
|
+
cookies[:beanstalkd_view_notice] = "Error deleting Job #{params[:job_id]}"
|
123
130
|
redirect url("/tube/#{params[:tube]}")
|
124
131
|
end
|
125
132
|
rescue Beanstalk::NotConnected => @error
|
@@ -131,14 +138,14 @@ module BeanstalkdView
|
|
131
138
|
begin
|
132
139
|
response = beanstalk.pause_tube(params[:tube], params[:delay].to_i)
|
133
140
|
if response
|
134
|
-
|
141
|
+
cookies[:beanstalkd_view_notice] = "Paused #{params[:tube]}. No jobs will be reserved for #{params[:delay].to_i} seconds."
|
135
142
|
redirect url("/tube/#{params[:tube]}")
|
136
143
|
else
|
137
|
-
|
144
|
+
cookies[:beanstalkd_view_notice] = "Error pausing #{params[:tube]}."
|
138
145
|
redirect url("/tube/#{params[:tube]}")
|
139
146
|
end
|
140
147
|
rescue NameError => @error
|
141
|
-
|
148
|
+
cookies[:beanstalkd_view_notice] = "The pause_tube method is currently not implemented by this version of beanstalk-client."
|
142
149
|
redirect url("/tube/#{params[:tube]}")
|
143
150
|
rescue Beanstalk::NotConnected => @error
|
144
151
|
erb :error
|
@@ -152,10 +159,10 @@ module BeanstalkdView
|
|
152
159
|
response = conn.kick(params[:bound].to_i)
|
153
160
|
end
|
154
161
|
if response
|
155
|
-
|
162
|
+
cookies[:beanstalkd_view_notice] = "Kicked #{params[:tube]} for #{response} jobs."
|
156
163
|
redirect url("/tube/#{params[:tube]}")
|
157
164
|
else
|
158
|
-
|
165
|
+
cookies[:beanstalkd_view_notice] = "Error kicking #{params[:tube]}."
|
159
166
|
redirect url("/tube/#{params[:tube]}")
|
160
167
|
end
|
161
168
|
rescue Beanstalk::NotConnected => @error
|
@@ -163,21 +170,31 @@ module BeanstalkdView
|
|
163
170
|
end
|
164
171
|
end
|
165
172
|
|
166
|
-
|
167
|
-
|
168
|
-
send_file file
|
173
|
+
def url_path(*path_parts)
|
174
|
+
[ path_prefix, path_parts ].join("/").squeeze('/')
|
169
175
|
end
|
170
|
-
|
176
|
+
alias_method :u, :url_path
|
177
|
+
|
178
|
+
def path_prefix
|
179
|
+
request.env['SCRIPT_NAME']
|
180
|
+
end
|
181
|
+
|
182
|
+
def notice_message
|
183
|
+
message = cookies[:beanstalkd_view_notice]
|
184
|
+
cookies[:beanstalkd_view_notice] = ''
|
185
|
+
message
|
186
|
+
end
|
187
|
+
|
171
188
|
private
|
172
|
-
|
189
|
+
|
173
190
|
# Return the stats data in a format for the Bluff JS UI Charts
|
174
|
-
def get_chart_data_hash(
|
191
|
+
def get_chart_data_hash(tube_set)
|
175
192
|
chart_data = Hash.new
|
176
193
|
chart_data["total_jobs_data"] = Hash.new
|
177
194
|
chart_data["buried_jobs_data"] = Hash.new
|
178
195
|
chart_data["total_jobs_data"]["items"] = Array.new
|
179
196
|
chart_data["buried_jobs_data"]["items"] = Array.new
|
180
|
-
tube_set
|
197
|
+
tube_set.each do |tube|
|
181
198
|
begin
|
182
199
|
stats = beanstalk.stats_tube(tube)
|
183
200
|
#total_jobs
|
@@ -12,10 +12,10 @@
|
|
12
12
|
<tbody>
|
13
13
|
<% @tubes.keys.each do |key| %>
|
14
14
|
<% @tubes[key].each do |tube| %>
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
<tr>
|
16
|
+
<td><%= key %></td>
|
17
|
+
<td><a href="<%= u("/tube/#{tube}") %>"><%= tube %></a></td>
|
18
|
+
</tr>
|
19
19
|
<% end %>
|
20
20
|
<% end %>
|
21
21
|
</tbody>
|
@@ -269,8 +269,8 @@
|
|
269
269
|
<div class="span6">
|
270
270
|
<div class="span6">
|
271
271
|
<h3>Add Job</h3>
|
272
|
-
<form id="add_job_form" class="well" name="add_job_form" action="<%=
|
273
|
-
<input id="form_tube_name" type="text" class="span3" placeholder="Tube name" name="tube">
|
272
|
+
<form id="add_job_form" class="well" name="add_job_form" action="<%= u("/add_job") %>" method="POST">
|
273
|
+
<input id="form_tube_name" type="text" class="span3" placeholder="Tube name" name="tube" data-provide="typeahead" autocomplete="off">
|
274
274
|
<input id="form_job_priority" type="text" class="span3" placeholder="Priority, e.g. 65536" name="priority">
|
275
275
|
<input id="form_job_delay" type="text" class="span3" placeholder="Delay, e.g. 0" name="delay">
|
276
276
|
<input id="form_job_ttr" type="text" class="span3" placeholder="TTR, e.g. 120" name="ttr">
|
@@ -335,6 +335,13 @@ $(document).ready(function(){
|
|
335
335
|
draw_pie_chart('buried_jobs_chart', buried_jobs_data);
|
336
336
|
$("#buried_jobs_container").css('visibility', 'visible');
|
337
337
|
<% end %>
|
338
|
+
|
339
|
+
//Setup Typeahead For Tube Names on Add Job Form
|
340
|
+
var tubeNames = [];
|
341
|
+
<% @tube_set.each do |tube| %>
|
342
|
+
tubeNames.push('<%=tube%>');
|
343
|
+
<% end %>
|
344
|
+
$('#form_tube_name').typeahead({source: tubeNames});
|
338
345
|
});
|
339
346
|
</script>
|
340
347
|
|
@@ -3,16 +3,16 @@
|
|
3
3
|
<html>
|
4
4
|
<head>
|
5
5
|
<title>Beanstalkd View - <%= BeanstalkdView::VERSION %></title>
|
6
|
-
<link rel="stylesheet" type="text/css" href="<%=
|
7
|
-
<link rel="stylesheet" type="text/css" href="<%=
|
6
|
+
<link rel="stylesheet" type="text/css" href="<%= u('/bootstrap/css/bootstrap.min.css') %>"/>
|
7
|
+
<link rel="stylesheet" type="text/css" href="<%= u('/bootstrap/css/overrides.css') %>"/>
|
8
8
|
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
9
|
-
<script type="text/javascript" src="<%=
|
10
|
-
<script type="text/javascript" src="<%=
|
11
|
-
<script type="text/javascript" src="<%=
|
12
|
-
<script type="text/javascript" src="<%=
|
13
|
-
<script language="javascript" src="<%=
|
14
|
-
<script language="javascript" src="<%=
|
15
|
-
<!--[if IE]><script language="javascript" src="<%=
|
9
|
+
<script type="text/javascript" src="<%= u('/js/jquery-1.7.1.min.js') %>"></script>
|
10
|
+
<script type="text/javascript" src="<%= u('/bootstrap/js/bootstrap.min.js') %>"></script>
|
11
|
+
<script type="text/javascript" src="<%= u('/js/json2.js') %>"></script>
|
12
|
+
<script type="text/javascript" src="<%= u('/js/peek_jobs.js') %>"></script>
|
13
|
+
<script language="javascript" src="<%= u('/js/bluff/js-class.js') %>"></script>
|
14
|
+
<script language="javascript" src="<%= u('/js/bluff/bluff-min.js') %>"></script>
|
15
|
+
<!--[if IE]><script language="javascript" src="<%= u('/js/bluff/excanvas.js') %>"></script><![endif]-->
|
16
16
|
<script type="text/javascript">
|
17
17
|
<!-- Enable Tooltips -->
|
18
18
|
$(document).ready(function() {
|
@@ -25,20 +25,21 @@
|
|
25
25
|
<div class="navbar">
|
26
26
|
<div class="navbar-inner">
|
27
27
|
<div class="container">
|
28
|
-
<a class="brand" href="<%=
|
28
|
+
<a class="brand" href="<%= u("/") %>">Beanstalkd View - <%= BeanstalkdView::VERSION %></a>
|
29
29
|
</div>
|
30
30
|
</div>
|
31
31
|
</div>
|
32
32
|
|
33
33
|
<div class="container">
|
34
34
|
|
35
|
-
<%
|
35
|
+
<% message = notice_message %>
|
36
|
+
<% if message and not message.empty? %>
|
36
37
|
<div id='flash' class='notice'>
|
37
38
|
<div class="row">
|
38
39
|
<div class="span12">
|
39
40
|
<div class="alert alert-success">
|
40
41
|
<h4 class="alert-heading">Notice:</h4>
|
41
|
-
<%=
|
42
|
+
<%= message %>
|
42
43
|
</div>
|
43
44
|
</div>
|
44
45
|
</div>
|
@@ -87,15 +87,15 @@
|
|
87
87
|
|
88
88
|
<div class="span6">
|
89
89
|
<h3>Pause Tube</h3>
|
90
|
-
<form class="well form-inline" name="pause_form" action="<%=
|
90
|
+
<form class="well form-inline" name="pause_form" action="<%= u("/pause") %>" method="POST">
|
91
91
|
<input id="form_tube_name" type="hidden" name="tube" value="<%= @tube %>">
|
92
|
-
<input id="form_url_base" type="hidden" name="url_base" value="<%=
|
92
|
+
<input id="form_url_base" type="hidden" name="url_base" value="<%= u("/") %>">
|
93
93
|
<input type="text" class="span3" placeholder="Number of seconds to wait" name="delay">
|
94
94
|
<button type="submit" class="btn">Pause</button>
|
95
95
|
</form>
|
96
96
|
|
97
97
|
<h3>Kick Tube</h3>
|
98
|
-
<form class="well form-inline" name="kick_form" action="<%=
|
98
|
+
<form class="well form-inline" name="kick_form" action="<%= u("/kick") %>" method="POST">
|
99
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>
|
data/lib/beanstalkd_view.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,43 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sinatra-contrib
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.3.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.0
|
25
46
|
- !ruby/object:Gem::Dependency
|
26
47
|
name: beanstalk-client
|
27
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
28
49
|
none: false
|
29
50
|
requirements:
|
30
51
|
- - ! '>='
|
@@ -32,10 +53,15 @@ dependencies:
|
|
32
53
|
version: 1.1.1
|
33
54
|
type: :runtime
|
34
55
|
prerelease: false
|
35
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.1
|
36
62
|
- !ruby/object:Gem::Dependency
|
37
63
|
name: vegas
|
38
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
39
65
|
none: false
|
40
66
|
requirements:
|
41
67
|
- - ~>
|
@@ -43,10 +69,15 @@ dependencies:
|
|
43
69
|
version: 0.1.2
|
44
70
|
type: :runtime
|
45
71
|
prerelease: false
|
46
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.1.2
|
47
78
|
- !ruby/object:Gem::Dependency
|
48
79
|
name: json
|
49
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
50
81
|
none: false
|
51
82
|
requirements:
|
52
83
|
- - ! '>='
|
@@ -54,10 +85,15 @@ dependencies:
|
|
54
85
|
version: '0'
|
55
86
|
type: :runtime
|
56
87
|
prerelease: false
|
57
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
58
94
|
- !ruby/object:Gem::Dependency
|
59
95
|
name: rake
|
60
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
61
97
|
none: false
|
62
98
|
requirements:
|
63
99
|
- - ! '>='
|
@@ -65,10 +101,15 @@ dependencies:
|
|
65
101
|
version: '0'
|
66
102
|
type: :development
|
67
103
|
prerelease: false
|
68
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
69
110
|
- !ruby/object:Gem::Dependency
|
70
111
|
name: rack-test
|
71
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
72
113
|
none: false
|
73
114
|
requirements:
|
74
115
|
- - ! '>='
|
@@ -76,10 +117,15 @@ dependencies:
|
|
76
117
|
version: '0'
|
77
118
|
type: :development
|
78
119
|
prerelease: false
|
79
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
80
126
|
- !ruby/object:Gem::Dependency
|
81
127
|
name: rspec
|
82
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
83
129
|
none: false
|
84
130
|
requirements:
|
85
131
|
- - ! '>='
|
@@ -87,10 +133,15 @@ dependencies:
|
|
87
133
|
version: '0'
|
88
134
|
type: :development
|
89
135
|
prerelease: false
|
90
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
91
142
|
- !ruby/object:Gem::Dependency
|
92
143
|
name: capybara
|
93
|
-
requirement:
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
94
145
|
none: false
|
95
146
|
requirements:
|
96
147
|
- - ! '>='
|
@@ -98,7 +149,12 @@ dependencies:
|
|
98
149
|
version: '0'
|
99
150
|
type: :development
|
100
151
|
prerelease: false
|
101
|
-
version_requirements:
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
102
158
|
description: A Sinatra app to view/manage beanstalkd queues that can be embedded in
|
103
159
|
a Rails app similar to what's available in Resque
|
104
160
|
email: dennis.kuczynski@gmail.com
|
@@ -149,15 +205,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
205
|
- - ! '>='
|
150
206
|
- !ruby/object:Gem::Version
|
151
207
|
version: '0'
|
208
|
+
segments:
|
209
|
+
- 0
|
210
|
+
hash: 2542161363701454031
|
152
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
212
|
none: false
|
154
213
|
requirements:
|
155
214
|
- - ! '>='
|
156
215
|
- !ruby/object:Gem::Version
|
157
216
|
version: '0'
|
217
|
+
segments:
|
218
|
+
- 0
|
219
|
+
hash: 2542161363701454031
|
158
220
|
requirements: []
|
159
221
|
rubyforge_project:
|
160
|
-
rubygems_version: 1.8.
|
222
|
+
rubygems_version: 1.8.24
|
161
223
|
signing_key:
|
162
224
|
specification_version: 3
|
163
225
|
summary: A Sinatra app to view/manage beanstalkd queues that can be embedded in a
|