misha-resque-cleaner 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +76 -0
- data/LICENSE +20 -0
- data/README.md +330 -0
- data/Rakefile +38 -0
- data/lib/resque-cleaner.rb +1 -0
- data/lib/resque_cleaner.rb +307 -0
- data/lib/resque_cleaner/server.rb +266 -0
- data/lib/resque_cleaner/server/public/cleaner.css +64 -0
- data/lib/resque_cleaner/server/views/_limiter.erb +13 -0
- data/lib/resque_cleaner/server/views/_paginate.erb +54 -0
- data/lib/resque_cleaner/server/views/_stats.erb +44 -0
- data/lib/resque_cleaner/server/views/cleaner.erb +25 -0
- data/lib/resque_cleaner/server/views/cleaner_exec.erb +8 -0
- data/lib/resque_cleaner/server/views/cleaner_list.erb +179 -0
- data/test/redis-test.conf +115 -0
- data/test/resque_cleaner_test.rb +206 -0
- data/test/resque_web_test.rb +66 -0
- data/test/test_helper.rb +131 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1405bf5e1ebe278cb94cd251a5d9cb0336aff9c9
|
4
|
+
data.tar.gz: 85f0196dd01ea54e55a153292bf8b45d4a132142
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7b9a7bc170754c7d0d217403f05d012514ebbb559c4ad5bb515d295c7f547aff27925777eb337039cd03e57f40efc2902101f6f9c89ec417836fcd1baf4801b
|
7
|
+
data.tar.gz: 14a6175730bdfbb787b490129820e007191ba15e877fcf7d2677abfeddabdfc5349f41cba8fae7096308038e5154283e292c9bc487e92f71503f7c2e0345f7a7
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
## 0.3.0 (2014-05-27)
|
2
|
+
|
3
|
+
* Search by regex (#27)
|
4
|
+
* Show stats by exception (#29)
|
5
|
+
* Stop supporting ruby 1.8.x and 1.9.2
|
6
|
+
* Escape query parameters (#30)
|
7
|
+
|
8
|
+
## 0.2.12 (2013-12-03)
|
9
|
+
|
10
|
+
* Remove Resque::Helpers include (#23)
|
11
|
+
* Tweak Gemspec (#24)
|
12
|
+
* Don't use yaml format to show arguments
|
13
|
+
* Tweak README
|
14
|
+
|
15
|
+
## 0.2.11 (2013-07-19)
|
16
|
+
|
17
|
+
* Use transaction for retry-and-clear (#22).
|
18
|
+
* Fix for CI
|
19
|
+
|
20
|
+
## 0.2.10 (2012-10-15)
|
21
|
+
|
22
|
+
* Bug fix: use URL helper to support resque-web which is not hosted under '/'.
|
23
|
+
|
24
|
+
## 0.2.9 (2012-05-10)
|
25
|
+
|
26
|
+
* Make limiter configurable on resque-web.
|
27
|
+
|
28
|
+
## 0.2.8 (2012-03-19)
|
29
|
+
|
30
|
+
* UI tweak (#15)
|
31
|
+
|
32
|
+
## 0.2.7 (2012-01-17)
|
33
|
+
|
34
|
+
* Support Travis CI
|
35
|
+
* Support failure jobs without payload information (#11).
|
36
|
+
|
37
|
+
## 0.2.6 (2011-08-23)
|
38
|
+
|
39
|
+
* Follow the latest resque for date format.
|
40
|
+
|
41
|
+
## 0.2.5 (2011-05-05)
|
42
|
+
|
43
|
+
* BUGFIX: Pagination has been broken.
|
44
|
+
* Dump a list as JSON format.
|
45
|
+
|
46
|
+
## 0.2.4 (2011-04-19)
|
47
|
+
|
48
|
+
* BUGFIX: "Select All" ignores exception filter.
|
49
|
+
|
50
|
+
## 0.2.3 (2011-04-11)
|
51
|
+
|
52
|
+
* Exception filter.
|
53
|
+
|
54
|
+
## 0.2.2 (2011-04-07)
|
55
|
+
|
56
|
+
* Changed a way to load yajl/json\_gem.
|
57
|
+
|
58
|
+
## 0.2.1 (2011-04-06)
|
59
|
+
|
60
|
+
* BUGFIX: Bulk action didn't work properly when you select all jobs.
|
61
|
+
* Removed absolute paths from html.
|
62
|
+
|
63
|
+
## 0.2.0 (2011-04-06)
|
64
|
+
|
65
|
+
* Extended with resque-web
|
66
|
+
|
67
|
+
## 0.1.1 (2010-12-30)
|
68
|
+
|
69
|
+
* Fixed for ruby 1.9.2
|
70
|
+
* Fixed a bug on #retried? method
|
71
|
+
|
72
|
+
## 0.1.0 (2010-11-24)
|
73
|
+
|
74
|
+
* First official release
|
75
|
+
|
76
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Tatsuya Ono
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,330 @@
|
|
1
|
+
ResqueCleaner
|
2
|
+
=============
|
3
|
+
|
4
|
+
[github.com/ono/resque-cleaner](https://github.com/ono/resque-cleaner)
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
ResqueCleaner is a [Resque](https://github.com/defunkt/resque) plugin which
|
10
|
+
aims to help you to clean up failed jobs on Resque by:
|
11
|
+
|
12
|
+
* Showing stats of failed jobs
|
13
|
+
* Retrying failed jobs
|
14
|
+
* Removing failed jobs
|
15
|
+
* Filtering failed jobs
|
16
|
+
|
17
|
+
|
18
|
+
Installation
|
19
|
+
------------
|
20
|
+
|
21
|
+
Install as a gem:
|
22
|
+
|
23
|
+
$ gem install resque-cleaner
|
24
|
+
|
25
|
+
|
26
|
+
Resque-Web integration
|
27
|
+
----------------------
|
28
|
+
|
29
|
+
![Screen 1](https://github.com/ono/resque-cleaner/raw/master/misc/resque-cleaner-main.png)
|
30
|
+
![Screen 2](misc/resque-cleaner-list-with-regex.png)
|
31
|
+
|
32
|
+
|
33
|
+
Configuration
|
34
|
+
-------------
|
35
|
+
|
36
|
+
At first, you have to load ResqueCleaner to enable the Cleaner tab. Here is
|
37
|
+
an example step.
|
38
|
+
|
39
|
+
1. Create a configuration file for resque-web
|
40
|
+
<br/>```touch [app_dir]/config/resque-web.rb```
|
41
|
+
|
42
|
+
2. Add the following line into the file
|
43
|
+
<br/>```require 'resque-cleaner'```
|
44
|
+
|
45
|
+
3. Then pass the file when you start resque-web
|
46
|
+
<br/>```% resque-web [app_dir]/config/resque-web.rb```
|
47
|
+
|
48
|
+
You can also configure [limiter](https://github.com/ono/resque-cleaner#limiter)
|
49
|
+
in the file.
|
50
|
+
|
51
|
+
e.g.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require 'resque-cleaner'
|
55
|
+
module Resque::Plugins
|
56
|
+
ResqueCleaner::Limiter.default_maximum = 10_000
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
Console
|
61
|
+
-------
|
62
|
+
|
63
|
+
Hopefully a situation of your failed jobs is simple enough to get figured out through
|
64
|
+
the web interface. But, if not, a powerful filtering feature of ResqueCleaner may help
|
65
|
+
you to understand what is going on with your console(irb).
|
66
|
+
|
67
|
+
**Create Instance**
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
> cleaner = Resque::Plugins::ResqueCleaner.new
|
71
|
+
```
|
72
|
+
|
73
|
+
**Show Stats**
|
74
|
+
|
75
|
+
Shows stats of failed jobs grouped by date.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
> cleaner.stats_by_date
|
79
|
+
2009/03/13: 6
|
80
|
+
2009/11/13: 14
|
81
|
+
2010/08/13: 22
|
82
|
+
total: 42
|
83
|
+
=> {'2009/03/10' => 6, ...}
|
84
|
+
```
|
85
|
+
|
86
|
+
You could also group them by class.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
> cleaner.stats_by_class
|
90
|
+
BadJob: 3
|
91
|
+
HorribleJob: 7
|
92
|
+
total: 10
|
93
|
+
=> {'BadJob' => 3, ...}
|
94
|
+
```
|
95
|
+
|
96
|
+
Or you could also group them by exception.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
> cleaner.stats_by_exception
|
100
|
+
RuntimeError: 35
|
101
|
+
SyntaxError: 7
|
102
|
+
total: 42
|
103
|
+
=> {'RuntimeError' => 35, ...}
|
104
|
+
```
|
105
|
+
|
106
|
+
You can get the ones filtered with a block: it targets only jobs which the block
|
107
|
+
evaluates true.
|
108
|
+
|
109
|
+
e.g. Show stats only of jobs entered with some arguments:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
> cleaner.stats_by_date {|j| j["payload"]["args"].size > 0}
|
113
|
+
2009/03/13: 3
|
114
|
+
2009/11/13: 7
|
115
|
+
2010/08/13: 11
|
116
|
+
total: 22
|
117
|
+
=> {'2009/03/10' => 3, ...}
|
118
|
+
```
|
119
|
+
|
120
|
+
A convenience helper for searching for failed jobs which satisfy a
|
121
|
+
regular expression:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
cleaner.select_by_regex(/Jason/) # => all failed jobs that have "Jason" in them
|
125
|
+
```
|
126
|
+
|
127
|
+
**Retry(Requeue) Jobs**
|
128
|
+
|
129
|
+
You can retry all failed jobs with this method.
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
> cleaner.requeue
|
133
|
+
```
|
134
|
+
|
135
|
+
Of course, you can filter jobs with a block; it requeues only jobs which the
|
136
|
+
block evaluates true.
|
137
|
+
|
138
|
+
e.g. Retry only jobs with some arguments:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
> cleaner.requeue {|j| j["payload"]["args"].size > 0}
|
142
|
+
```
|
143
|
+
|
144
|
+
The job hash is extended with a module which defines some useful methods. You
|
145
|
+
can use it in the block.
|
146
|
+
|
147
|
+
e.g. Retry only jobs entered within a day:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
> cleaner.requeue {|j| j.after?(1.day.ago)}
|
151
|
+
```
|
152
|
+
|
153
|
+
e.g. Retry EmailJob entered with arguments within 3 days:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
> cleaner.requeue {|j| j.after?(3.days.ago) && j.klass?(EmailJob) && j["payload"]["args"].size>0}
|
157
|
+
```
|
158
|
+
|
159
|
+
See Helper Methods section bellow for more information.
|
160
|
+
|
161
|
+
NOTE:
|
162
|
+
[1.day.ago](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/numeric/time.rb)
|
163
|
+
is not in standard library. Using it for making explanation more understandable. It is equivalent to `Time.now - 60*60*24*3`.
|
164
|
+
|
165
|
+
**Clear Jobs**
|
166
|
+
|
167
|
+
You can clear all failed jobs with this method:
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
> cleaner.clear
|
171
|
+
```
|
172
|
+
|
173
|
+
Like you can do with the retry method, the clear method takes a block. Here are
|
174
|
+
some examples:
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
> cleaner.clear {|j| j.retried?}
|
178
|
+
=> clears all jobs already retried and returns number of the jobs.
|
179
|
+
|
180
|
+
> cleaner.clear {|j| j.queue?(:low) && j.before?('2010-10-10')}
|
181
|
+
=> clears all jobs entried in :low queue before 10th October, 2010.
|
182
|
+
|
183
|
+
> cleaner.clear {|j| j.exception?("RuntimeError") && j.queue?(:low)}
|
184
|
+
=> clears all jobs raised RuntimeError and queued :low queue
|
185
|
+
```
|
186
|
+
|
187
|
+
**Retry and Clear Jobs**
|
188
|
+
|
189
|
+
You can retry(requeue) and clear failed jobs at the same time; just pass true
|
190
|
+
as an argument.
|
191
|
+
|
192
|
+
e.g. Retry EmailJob and remove from failed jobs:
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
> cleaner.requeue(true) {|j| j.klass?(EmailJob)}
|
196
|
+
```
|
197
|
+
|
198
|
+
**Retry with other queue**
|
199
|
+
|
200
|
+
You can requeue failed jobs into other queue. In this way, you can retry failed
|
201
|
+
jobs without blocking jobs being entered by your service running in the live.
|
202
|
+
|
203
|
+
e.g. Retry failed jobs on :retry queue
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
> cleaner.requeue(false, :queue => :retry)
|
207
|
+
```
|
208
|
+
|
209
|
+
Don't forget to launch resque worker for the queue.
|
210
|
+
|
211
|
+
% QUEUE=retry rake resque:work
|
212
|
+
|
213
|
+
**Select Jobs**
|
214
|
+
|
215
|
+
You can just select the jobs of course. Here are some examples:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
> cleaner.select {|j| j["payload"]["args"][0]=="Johonson"}
|
219
|
+
> cleaner.select {|j| j.after?(2.days.ago)}
|
220
|
+
> cleaner.select #=> returns all jobs
|
221
|
+
```
|
222
|
+
|
223
|
+
**Helper Methods**
|
224
|
+
|
225
|
+
Here is a list of methods a failed job retained through ResqueCleaner has:
|
226
|
+
|
227
|
+
retried?: returns true if the job has already been retried.
|
228
|
+
requeued?: alias of retried?.
|
229
|
+
before?(time): returns true if the job failed before the time.
|
230
|
+
after?(time): returns true if the job failed after the time.
|
231
|
+
klass?(klass_or_name): returns true if the class of job matches.
|
232
|
+
queue?(queue_name): returns true if the queue of job matches.
|
233
|
+
exception?(exception_name): returns true if the exception matches.
|
234
|
+
|
235
|
+
|
236
|
+
Failed Job
|
237
|
+
-----------
|
238
|
+
|
239
|
+
Here is a sample of failed jobs:
|
240
|
+
|
241
|
+
{"failed_at": "2009/03/13 00:00:00",
|
242
|
+
"payload": {"args": ["Johnson"], "class": "BadJob"},
|
243
|
+
"queue": "jobs",
|
244
|
+
"worker": "localhost:7327:jobs,jobs2",
|
245
|
+
"exception": "RuntimeError",
|
246
|
+
"error": "Bad job, Johnson",
|
247
|
+
"backtrace":
|
248
|
+
["./test/test_helper.rb:108:in `perform'",
|
249
|
+
"/opt/local/lib/ruby/gems/1.8/gems/resque-1.10.0/lib/resque/job.rb:133:in `perform'",
|
250
|
+
"/opt/local/lib/ruby/gems/1.8/gems/resque-1.10.0/lib/resque/worker.rb:157:in `perform'",
|
251
|
+
"/opt/local/lib/ruby/gems/1.8/gems/resque-1.10.0/lib/resque/worker.rb:124:in `work'",
|
252
|
+
"....(omitted)....",
|
253
|
+
"./test/test_helper.rb:41",
|
254
|
+
"test/resque_cleaner_test.rb:3"]
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
Limiter
|
259
|
+
-------
|
260
|
+
|
261
|
+
ResqueCleaner expects a disaster situation like a huge number of failed jobs are
|
262
|
+
out there. Since ResqueCleaner's filter function is running on your application
|
263
|
+
process but on your Redis, it would not respond ages if you try to deal with all
|
264
|
+
of those jobs.
|
265
|
+
|
266
|
+
ResqueCleaner supposes recent jobs are more important than old jobs. Therefore
|
267
|
+
ResqueCleaner deals with **ONLY LAST X(default=1000) JOBS**. In this way, you
|
268
|
+
could avoid slow responses. You can change the number through `limiter` attribute.
|
269
|
+
|
270
|
+
Let's see how it works with an following example.
|
271
|
+
|
272
|
+
**Sample Situation**
|
273
|
+
|
274
|
+
* Number of failed jobs: 100,000
|
275
|
+
|
276
|
+
Default limiter is 1000 so that the limiter returns 1000 as a count.
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
> cleaner.limiter.count
|
280
|
+
=> 1,000
|
281
|
+
> cleaner.failure.count
|
282
|
+
=> 100,000
|
283
|
+
```
|
284
|
+
|
285
|
+
You could know if the limiter is on with on? method.
|
286
|
+
|
287
|
+
```ruby
|
288
|
+
> cleaner.limiter.on?
|
289
|
+
=> true
|
290
|
+
```
|
291
|
+
|
292
|
+
You can change the maximum number of the limiter with maximum attribute.
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
> cleaner.limiter.maximum = 3000
|
296
|
+
=> 3,000
|
297
|
+
> cleaner.limiter.count
|
298
|
+
=> 3,000
|
299
|
+
> cleaner.limiter.on?
|
300
|
+
=> true
|
301
|
+
```
|
302
|
+
|
303
|
+
With limiter, ResqueCleaner's filtering targets only the last X(3000 in this
|
304
|
+
sample) failed jobs.
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
> cleaner.select.size
|
308
|
+
=> 3,000
|
309
|
+
```
|
310
|
+
|
311
|
+
The clear\_stale method deletes all jobs entered prior to the last X(3000 in
|
312
|
+
this sample) failed jobs. This calls Redis API and no iteration occurs on Ruby
|
313
|
+
application; it should be quick even if there are huge number of failed jobs.
|
314
|
+
|
315
|
+
```ruby
|
316
|
+
> cleaner.clear_stale
|
317
|
+
> cleaner.failure.count
|
318
|
+
=> 3,000
|
319
|
+
> cleaner.limiter.count
|
320
|
+
=> 3,000
|
321
|
+
> cleaner.limiter.on?
|
322
|
+
=> false
|
323
|
+
```
|
324
|
+
|
325
|
+
Many Thanks!
|
326
|
+
------------
|
327
|
+
|
328
|
+
To our [Contributors](https://github.com/ono/resque-cleaner/contributors)
|
329
|
+
|
330
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Setup
|
3
|
+
#
|
4
|
+
|
5
|
+
# load 'tasks/redis.rake'
|
6
|
+
#require 'rake/testtask'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift 'lib'
|
9
|
+
#require 'resque/tasks'
|
10
|
+
|
11
|
+
def command?(command)
|
12
|
+
system("type #{command} > /dev/null 2>&1")
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
#
|
17
|
+
# Tests
|
18
|
+
#
|
19
|
+
|
20
|
+
task :default => :test
|
21
|
+
|
22
|
+
desc "Run the test suite"
|
23
|
+
task :test do
|
24
|
+
rg = command?(:rg)
|
25
|
+
Dir['test/**/*_test.rb'].each do |f|
|
26
|
+
rg ? sh("rg #{f}") : ruby(f)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if command? :kicker
|
31
|
+
desc "Launch Kicker (like autotest)"
|
32
|
+
task :kicker do
|
33
|
+
puts "Kicking... (ctrl+c to cancel)"
|
34
|
+
exec "kicker -e rake test lib examples"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|