resque_manager 3.3.1 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc0f5d6ae5c0b8f07d40fb0255213f896e000b55
4
- data.tar.gz: 80b0ec095f8ab9f7f1690528c116f10606c22fed
3
+ metadata.gz: 735b88a6f88951d523090c3533a1dcac2e753ae9
4
+ data.tar.gz: 7647c53321229d8920c64fc7364982afb5e1a80c
5
5
  SHA512:
6
- metadata.gz: 2eb3aad6bde5be68c075529a24f69b5220ddafaecfa32c0cf5ce640d37465d74f1770a475a7c8df7b9d49c15d5815a36d5c1314bfdea512baf05eea669366d6a
7
- data.tar.gz: d864075ab6c290d213ba0ffe6bcd3b71d29822f80e2502067b8c709b5e2851b69a15f5fdfb042599f3956aae0fafd9dabf63d7c864e47fc1535560a2f54d35f4
6
+ metadata.gz: 20712d2a060222720058f5ca3d8ea02157b0c3aa41a67a1bd9055fffca605d4a368c8501cb0ee6eedd19311687372f234de44439cc7aed84e8c189673985bc23
7
+ data.tar.gz: ebfb572eaeab14c7ae4b726b628990bf562b6d2f65885f3e83aaedefd1c27e95a20db6ea9c5297ca8063b196e734a1bf65755f5de5807f9b2816a49aeddf4aee
@@ -1,313 +1,316 @@
1
- require 'resque'
2
- require 'resque/version'
3
- require 'digest/sha1'
1
+ # Only load this file if it's running from the server, not from a rake task starting a worker. Workers don't need the controller.
2
+ unless defined?($rails_rake_task) && $rails_rake_task
3
+ require 'resque'
4
+ require 'resque/version'
5
+ require 'digest/sha1'
4
6
 
5
7
 
6
- class ResqueManager::ResqueController < ApplicationController
7
- unloadable(self) #needed to prevent errors with authenticated system in dev env.
8
+ class ResqueManager::ResqueController < ApplicationController
9
+ unloadable(self) #needed to prevent errors with authenticated system in dev env.
8
10
 
9
- layout 'resque_manager/application'
11
+ layout 'resque_manager/application'
10
12
 
11
- before_filter :check_connection
13
+ before_filter :check_connection
12
14
 
13
- before_filter :get_cleaner, :only => [:cleaner, :cleaner_exec, :cleaner_list, :cleaner_stale, :cleaner_dump]
15
+ before_filter :get_cleaner, :only => [:cleaner, :cleaner_exec, :cleaner_list, :cleaner_stale, :cleaner_dump]
14
16
 
15
- def working
16
- render('_working')
17
- end
18
-
19
- def queues
20
- render('_queues', :locals => {:partial => nil})
21
- end
17
+ def working
18
+ render('_working')
19
+ end
22
20
 
23
- def poll
24
- @polling = true
25
- render(:text => (render_to_string(:action => "#{params[:page]}", :formats => [:html], :layout => false, :resque => Resque)).gsub(/\s{1,}/, ' '))
26
- end
21
+ def queues
22
+ render('_queues', :locals => {:partial => nil})
23
+ end
27
24
 
28
- def status_poll
29
- @polling = true
25
+ def poll
26
+ @polling = true
27
+ render(:text => (render_to_string(:action => "#{params[:page]}", :formats => [:html], :layout => false, :resque => Resque)).gsub(/\s{1,}/, ' '))
28
+ end
30
29
 
31
- @start = params[:start].to_i
32
- @end = @start + (params[:per_page] || 20)
33
- @statuses = Resque::Plugins::Status::Hash.statuses(@start, @end)
34
- @size = Resque::Plugins::Status::Hash.status_ids.size
30
+ def status_poll
31
+ @polling = true
35
32
 
36
- render(:text => (render_to_string(:action => 'statuses', :formats => [:html], :layout => false)))
37
- end
33
+ @start = params[:start].to_i
34
+ @end = @start + (params[:per_page] || 20)
35
+ @statuses = Resque::Plugins::Status::Hash.statuses(@start, @end)
36
+ @size = Resque::Plugins::Status::Hash.status_ids.size
38
37
 
39
- def remove_job
40
- # We can only dequeue a job when that job is in the same application as the UI.
41
- # Otherwise we get an error when we try to constantize a class that does not exist
42
- # in the application the UI is in.
43
- if ResqueManager.applications.blank?
44
- Resque.dequeue(params['class'].constantize, *Resque.decode(params['args']))
38
+ render(:text => (render_to_string(:action => 'statuses', :formats => [:html], :layout => false)))
45
39
  end
46
- redirect_to request.referrer
47
- end
48
-
49
- def stop_worker
50
- worker = find_worker(params[:worker])
51
- worker.quit if worker
52
- redirect_to workers_resque_path
53
- end
54
40
 
55
- def pause_worker
56
- worker = find_worker(params[:worker])
57
- worker.pause if worker
58
- redirect_to workers_resque_path
59
- end
41
+ def remove_job
42
+ # We can only dequeue a job when that job is in the same application as the UI.
43
+ # Otherwise we get an error when we try to constantize a class that does not exist
44
+ # in the application the UI is in.
45
+ if ResqueManager.applications.blank?
46
+ Resque.dequeue(params['class'].constantize, *Resque.decode(params['args']))
47
+ end
48
+ redirect_to request.referrer
49
+ end
60
50
 
61
- def continue_worker
62
- worker = find_worker(params[:worker])
63
- worker.continue if worker
64
- redirect_to workers_resque_path
65
- end
51
+ def stop_worker
52
+ worker = find_worker(params[:worker])
53
+ worker.quit if worker
54
+ redirect_to workers_resque_path
55
+ end
66
56
 
67
- def restart_worker
68
- worker = find_worker(params[:worker])
69
- worker.restart if worker
70
- redirect_to workers_resque_path
71
- end
57
+ def pause_worker
58
+ worker = find_worker(params[:worker])
59
+ worker.pause if worker
60
+ redirect_to workers_resque_path
61
+ end
72
62
 
73
- def start_worker
74
- Resque::Worker.start(params)
75
- redirect_to workers_resque_path
76
- end
63
+ def continue_worker
64
+ worker = find_worker(params[:worker])
65
+ worker.continue if worker
66
+ redirect_to workers_resque_path
67
+ end
77
68
 
78
- def stats
79
- unless params[:id]
80
- redirect_to(stats_resque_path(:id => 'resque'))
69
+ def restart_worker
70
+ worker = find_worker(params[:worker])
71
+ worker.restart if worker
72
+ redirect_to workers_resque_path
81
73
  end
82
74
 
83
- if params[:id] == 'txt'
84
- info = Resque.info
75
+ def start_worker
76
+ Resque::Worker.start(params)
77
+ redirect_to workers_resque_path
78
+ end
85
79
 
86
- stats = []
87
- stats << "resque.pending=#{info[:pending]}"
88
- stats << "resque.processed+=#{info[:processed]}"
89
- stats << "resque.failed+=#{info[:failed]}"
90
- stats << "resque.workers=#{info[:workers]}"
91
- stats << "resque.working=#{info[:working]}"
92
- Resque.queues.each do |queue|
93
- stats << "queues.#{queue}=#{Resque.size(queue)}"
80
+ def stats
81
+ unless params[:id]
82
+ redirect_to(stats_resque_path(:id => 'resque'))
94
83
  end
95
84
 
96
- render(:text => stats.join("</br>").html_safe)
97
- end
98
- end
99
-
100
- # resque-scheduler actions
85
+ if params[:id] == 'txt'
86
+ info = Resque.info
87
+
88
+ stats = []
89
+ stats << "resque.pending=#{info[:pending]}"
90
+ stats << "resque.processed+=#{info[:processed]}"
91
+ stats << "resque.failed+=#{info[:failed]}"
92
+ stats << "resque.workers=#{info[:workers]}"
93
+ stats << "resque.working=#{info[:working]}"
94
+ Resque.queues.each do |queue|
95
+ stats << "queues.#{queue}=#{Resque.size(queue)}"
96
+ end
101
97
 
102
- def schedule
103
- @farm_status = ResqueScheduler.farm_status
104
- end
98
+ render(:text => stats.join("</br>").html_safe)
99
+ end
100
+ end
105
101
 
106
- def schedule_requeue
107
- config = Resque.schedule[params['job_name']]
108
- Resque::Scheduler.enqueue_from_config(config)
109
- redirect_to overview_resque_path
110
- end
102
+ # resque-scheduler actions
111
103
 
112
- def add_scheduled_job
113
- errors = []
114
- if Resque.schedule.keys.include?(params[:name])
115
- errors << 'Name already exists.'
116
- end
117
- if params[:ip].blank?
118
- errors << 'You must enter an ip address for the server you want this job to run on.'
104
+ def schedule
105
+ @farm_status = ResqueScheduler.farm_status
119
106
  end
120
- if params[:cron].blank?
121
- errors << 'You must enter the cron schedule.'
122
- end
123
- if errors.blank?
124
- config = {params['name'] => {'class' => params['class'],
125
- 'ip' => params['ip'],
126
- 'cron' => params['cron'],
127
- 'args' => Resque.decode(params['args'].blank? ? nil : params['args']),
128
- 'description' => params['description']}
129
- }
130
- Resque.redis.rpush(:scheduled, Resque.encode(config))
131
- ResqueScheduler.restart(params['ip'])
132
- else
133
- flash[:error] = errors.join('<br>').html_safe
107
+
108
+ def schedule_requeue
109
+ config = Resque.schedule[params['job_name']]
110
+ Resque::Scheduler.enqueue_from_config(config)
111
+ redirect_to overview_resque_path
134
112
  end
135
- redirect_to schedule_resque_path
136
- end
137
113
 
138
- def remove_from_schedule
139
- Resque.list_range(:scheduled, 0, -0).each do |s|
140
- if s[params['job_name']]
141
- Resque.redis.lrem(:scheduled, 0, s.to_json)
142
- # Restart the scheduler on the server that has changed it's schedule
114
+ def add_scheduled_job
115
+ errors = []
116
+ if Resque.schedule.keys.include?(params[:name])
117
+ errors << 'Name already exists.'
118
+ end
119
+ if params[:ip].blank?
120
+ errors << 'You must enter an ip address for the server you want this job to run on.'
121
+ end
122
+ if params[:cron].blank?
123
+ errors << 'You must enter the cron schedule.'
124
+ end
125
+ if errors.blank?
126
+ config = {params['name'] => {'class' => params['class'],
127
+ 'ip' => params['ip'],
128
+ 'cron' => params['cron'],
129
+ 'args' => Resque.decode(params['args'].blank? ? nil : params['args']),
130
+ 'description' => params['description']}
131
+ }
132
+ Resque.redis.rpush(:scheduled, Resque.encode(config))
143
133
  ResqueScheduler.restart(params['ip'])
134
+ else
135
+ flash[:error] = errors.join('<br>').html_safe
144
136
  end
137
+ redirect_to schedule_resque_path
145
138
  end
146
- redirect_to schedule_resque_path
147
- end
148
139
 
149
- def start_scheduler
150
- ResqueScheduler.start(params[:ip])
151
- redirect_to schedule_resque_path
152
- end
140
+ def remove_from_schedule
141
+ Resque.list_range(:scheduled, 0, -0).each do |s|
142
+ if s[params['job_name']]
143
+ Resque.redis.lrem(:scheduled, 0, s.to_json)
144
+ # Restart the scheduler on the server that has changed it's schedule
145
+ ResqueScheduler.restart(params['ip'])
146
+ end
147
+ end
148
+ redirect_to schedule_resque_path
149
+ end
153
150
 
154
- def stop_scheduler
155
- ResqueScheduler.quit(params[:ip])
156
- redirect_to schedule_resque_path
157
- end
151
+ def start_scheduler
152
+ ResqueScheduler.start(params[:ip])
153
+ redirect_to schedule_resque_path
154
+ end
155
+
156
+ def stop_scheduler
157
+ ResqueScheduler.quit(params[:ip])
158
+ redirect_to schedule_resque_path
159
+ end
158
160
 
159
- # resque-status actions
161
+ # resque-status actions
160
162
 
161
- def statuses
162
- @start = params[:start].to_i
163
- @end = @start + (params[:per_page] || 20)
164
- @statuses = Resque::Plugins::Status::Hash.statuses(@start, @end)
165
- @size = Resque::Plugins::Status::Hash.status_ids.size
166
- respond_to do |format|
167
- format.js { render json: @statuses }
168
- format.json { render json: @statuses }
163
+ def statuses
164
+ @start = params[:start].to_i
165
+ @end = @start + (params[:per_page] || 20)
166
+ @statuses = Resque::Plugins::Status::Hash.statuses(@start, @end)
167
+ @size = Resque::Plugins::Status::Hash.status_ids.size
168
+ respond_to do |format|
169
+ format.js { render json: @statuses }
170
+ format.html { render :statuses }
171
+ end
169
172
  end
170
- end
171
173
 
172
- def clear_statuses
173
- Resque::Plugins::Status::Hash.clear
174
- redirect_to statuses_resque_path
175
- end
174
+ def clear_statuses
175
+ Resque::Plugins::Status::Hash.clear
176
+ redirect_to statuses_resque_path
177
+ end
176
178
 
177
- def status
178
- @status = Resque::Plugins::Status::Hash.get(params[:id])
179
- respond_to do |format|
180
- format.js { render json: @status }
181
- format.json { render json: @status }
179
+ def status
180
+ @status = Resque::Plugins::Status::Hash.get(params[:id])
181
+ respond_to do |format|
182
+ format.js { render json: @status }
183
+ format.html { render :status }
184
+ end
182
185
  end
183
- end
184
186
 
185
- def kill
186
- Resque::Plugins::Status::Hash.kill(params[:id])
187
- s = Resque::Plugins::Status::Hash.get(params[:id])
188
- s.status = 'killed'
189
- Resque::Plugins::Status::Hash.set(params[:id], s)
190
- redirect_to statuses_resque_path
191
- end
187
+ def kill
188
+ Resque::Plugins::Status::Hash.kill(params[:id])
189
+ s = Resque::Plugins::Status::Hash.get(params[:id])
190
+ s.status = 'killed'
191
+ Resque::Plugins::Status::Hash.set(params[:id], s)
192
+ redirect_to statuses_resque_path
193
+ end
192
194
 
193
- def cleaner
194
- load_cleaner_filter
195
+ def cleaner
196
+ load_cleaner_filter
195
197
 
196
- @jobs = @cleaner.select
197
- @stats, @total = {}, {"total" => 0, "1h" => 0, "3h" => 0, "1d" => 0, "3d" => 0, "7d" => 0}
198
- @jobs.each do |job|
199
- klass = job["payload"]["class"]
200
- failed_at = Time.parse job["failed_at"]
198
+ @jobs = @cleaner.select
199
+ @stats, @total = {}, {"total" => 0, "1h" => 0, "3h" => 0, "1d" => 0, "3d" => 0, "7d" => 0}
200
+ @jobs.each do |job|
201
+ klass = job["payload"]["class"]
202
+ failed_at = Time.parse job["failed_at"]
201
203
 
202
- @stats[klass] ||= {"total" => 0, "1h" => 0, "3h" => 0, "1d" => 0, "3d" => 0, "7d" => 0}
203
- items = [@stats[klass], @total]
204
+ @stats[klass] ||= {"total" => 0, "1h" => 0, "3h" => 0, "1d" => 0, "3d" => 0, "7d" => 0}
205
+ items = [@stats[klass], @total]
204
206
 
205
- items.each { |a| a["total"] += 1 }
206
- items.each { |a| a["1h"] += 1 } if failed_at >= hours_ago(1)
207
- items.each { |a| a["3h"] += 1 } if failed_at >= hours_ago(3)
208
- items.each { |a| a["1d"] += 1 } if failed_at >= hours_ago(24)
209
- items.each { |a| a["3d"] += 1 } if failed_at >= hours_ago(24*3)
210
- items.each { |a| a["7d"] += 1 } if failed_at >= hours_ago(24*7)
207
+ items.each { |a| a["total"] += 1 }
208
+ items.each { |a| a["1h"] += 1 } if failed_at >= hours_ago(1)
209
+ items.each { |a| a["3h"] += 1 } if failed_at >= hours_ago(3)
210
+ items.each { |a| a["1d"] += 1 } if failed_at >= hours_ago(24)
211
+ items.each { |a| a["3d"] += 1 } if failed_at >= hours_ago(24*3)
212
+ items.each { |a| a["7d"] += 1 } if failed_at >= hours_ago(24*7)
213
+ end
211
214
  end
212
- end
213
215
 
214
- def cleaner_list
215
- load_cleaner_filter
216
+ def cleaner_list
217
+ load_cleaner_filter
216
218
 
217
- block = filter_block
219
+ block = filter_block
218
220
 
219
- @failed = @cleaner.select(&block).reverse
221
+ @failed = @cleaner.select(&block).reverse
220
222
 
221
- url = "cleaner_list?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}"
222
- @dump_url = "cleaner_dump?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}"
223
- @paginate = ResqueManager::Paginate.new(@failed, url, params[:p].to_i)
223
+ url = "cleaner_list?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}"
224
+ @dump_url = "cleaner_dump?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}"
225
+ @paginate = ResqueManager::Paginate.new(@failed, url, params[:p].to_i)
224
226
 
225
- @klasses = @cleaner.stats_by_class.keys
226
- @exceptions = @cleaner.stats_by_exception.keys
227
- @count = @cleaner.select(&block).size
228
- end
227
+ @klasses = @cleaner.stats_by_class.keys
228
+ @exceptions = @cleaner.stats_by_exception.keys
229
+ @count = @cleaner.select(&block).size
230
+ end
229
231
 
230
- def cleaner_exec
231
- load_cleaner_filter
232
+ def cleaner_exec
233
+ load_cleaner_filter
232
234
 
233
- if params[:select_all_pages]!="1"
234
- @sha1 = {}
235
- params[:sha1].split(",").each { |s| @sha1[s] = true }
236
- end
235
+ if params[:select_all_pages]!="1"
236
+ @sha1 = {}
237
+ params[:sha1].split(",").each { |s| @sha1[s] = true }
238
+ end
237
239
 
238
- block = filter_block
240
+ block = filter_block
239
241
 
240
- @count =
241
- case params[:form_action]
242
- when "clear" then
243
- @cleaner.clear(&block)
244
- when "retry_and_clear" then
245
- @cleaner.requeue(true, &block)
246
- when "retry" then
247
- @cleaner.requeue(false, {}, &block)
248
- end
242
+ @count =
243
+ case params[:form_action]
244
+ when "clear" then
245
+ @cleaner.clear(&block)
246
+ when "retry_and_clear" then
247
+ @cleaner.requeue(true, &block)
248
+ when "retry" then
249
+ @cleaner.requeue(false, {}, &block)
250
+ end
249
251
 
250
- @link_url = "cleaner_list?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}"
251
- end
252
+ @link_url = "cleaner_list?c=#{@klass}&ex=#{@exception}&f=#{@from}&t=#{@to}"
253
+ end
252
254
 
253
- def cleaner_dump
254
- load_cleaner_filter
255
+ def cleaner_dump
256
+ load_cleaner_filter
255
257
 
256
- block = filter_block
257
- failures = @cleaner.select(&block)
258
- # pretty generate throws an error with the json gem on jruby
259
- output = JSON.pretty_generate(failures) rescue failures.to_json
260
- render :json => output
261
- end
258
+ block = filter_block
259
+ failures = @cleaner.select(&block)
260
+ # pretty generate throws an error with the json gem on jruby
261
+ output = JSON.pretty_generate(failures) rescue failures.to_json
262
+ render :json => output
263
+ end
262
264
 
263
- def cleaner_stale
264
- @cleaner.clear_stale
265
- redirect_to cleaner_resque_path
266
- end
265
+ def cleaner_stale
266
+ @cleaner.clear_stale
267
+ redirect_to cleaner_resque_path
268
+ end
267
269
 
268
270
 
269
- private
271
+ private
270
272
 
271
- def check_connection
272
- Resque.keys
273
- rescue Errno::ECONNREFUSED
274
- render(:template => 'resque_manager/resque/error', :layout => false, :locals => { :error => "Can't connect to Redis! (#{Resque.redis_id})" })
275
- false
276
- end
273
+ def check_connection
274
+ Resque.keys
275
+ rescue Errno::ECONNREFUSED
276
+ render(:template => 'resque_manager/resque/error', :layout => false, :locals => {:error => "Can't connect to Redis! (#{Resque.redis_id})"})
277
+ false
278
+ end
277
279
 
278
- def find_worker(worker)
279
- return nil if worker.blank?
280
- first_part, *rest = worker.split(':')
281
- first_part.gsub!(/_/, '.')
282
- Resque::Worker.find("#{first_part}:#{rest.join(':')}")
283
- end
280
+ def find_worker(worker)
281
+ return nil if worker.blank?
282
+ first_part, *rest = worker.split(':')
283
+ first_part.gsub!(/_/, '.')
284
+ Resque::Worker.find("#{first_part}:#{rest.join(':')}")
285
+ end
284
286
 
285
- # resque-cleaner methods
287
+ # resque-cleaner methods
286
288
 
287
- def get_cleaner
288
- @cleaner ||= Resque::Plugins::ResqueCleaner.new
289
- @cleaner.print_message = false
290
- @cleaner
291
- end
289
+ def get_cleaner
290
+ @cleaner ||= Resque::Plugins::ResqueCleaner.new
291
+ @cleaner.print_message = false
292
+ @cleaner
293
+ end
292
294
 
293
- def load_cleaner_filter
294
- @from = params[:f].blank? ? nil : params[:f]
295
- @to = params[:t].blank? ? nil : params[:t]
296
- @klass = params[:c].blank? ? nil : params[:c]
297
- @exception = params[:ex].blank? ? nil : params[:ex]
298
- end
295
+ def load_cleaner_filter
296
+ @from = params[:f].blank? ? nil : params[:f]
297
+ @to = params[:t].blank? ? nil : params[:t]
298
+ @klass = params[:c].blank? ? nil : params[:c]
299
+ @exception = params[:ex].blank? ? nil : params[:ex]
300
+ end
299
301
 
300
- def filter_block
301
- lambda { |j|
302
- (!@from || j.after?(hours_ago(@from))) &&
303
- (!@to || j.before?(hours_ago(@to))) &&
304
- (!@klass || j.klass?(@klass)) &&
305
- (!@exception || j.exception?(@exception)) &&
306
- (!@sha1 || @sha1[Digest::SHA1.hexdigest(j.to_json)])
307
- }
308
- end
302
+ def filter_block
303
+ lambda { |j|
304
+ (!@from || j.after?(hours_ago(@from))) &&
305
+ (!@to || j.before?(hours_ago(@to))) &&
306
+ (!@klass || j.klass?(@klass)) &&
307
+ (!@exception || j.exception?(@exception)) &&
308
+ (!@sha1 || @sha1[Digest::SHA1.hexdigest(j.to_json)])
309
+ }
310
+ end
309
311
 
310
- def hours_ago(h)
311
- Time.now - h.to_i*60*60
312
+ def hours_ago(h)
313
+ Time.now - h.to_i*60*60
314
+ end
312
315
  end
313
- end
316
+ end