resque-cleaner 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +4 -0
- data/lib/resque_cleaner/server/views/cleaner_list.erb +1 -0
- data/test/dump.rdb +0 -0
- data/test/resque_cleaner_test.rb +23 -23
- data/test/resque_web_test.rb +16 -10
- data/test/test_helper.rb +14 -36
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTkwNTk5MTJmZDU2MmM0OGEzZjFjMDA1NDZkYmM4OTQxNzc5MTg1NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODRlODRhODg1MmUzMWUzMzllMmJhY2RmZWU1MmQyYzU1NGJiNzE0Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTI0ZDAyY2MzMmFkZWM5MGYwZGI5YTA5Mzk3NzhiYTk5Njk5YTIzZWM0YzUy
|
10
|
+
ZmM4YTBjZWJhY2JiYTNmNDNkYjcwZjkxZjhmOTBlZmNmNjQ1MDM3NmIwNjcx
|
11
|
+
NmUzMWNjMzU0MDY5Y2MxOTE2ZDU1YjM0ZTdkOGNmOTkzY2ViMjY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzkxNjYyMzIzYWQ4ZWQxOTQzNzVmNDgwYjE0NzE4OGFlM2FhNDljYmJiOWE4
|
14
|
+
MjdkYWRjOTQ5NDlhMjBkZDI3ZDk1OTlkNThiYjU2NThlNTA2YTBkYTg1OTYx
|
15
|
+
NWViYWZmZTY3NmU1NTQzYzkxN2Q5ZjA0MmQ5NmFiMmNkNzYwOTg=
|
data/CHANGELOG.md
CHANGED
@@ -38,6 +38,7 @@
|
|
38
38
|
<input type="hidden" name="t" value="<%=@to%>" />
|
39
39
|
<input type="hidden" name="p" value="<%=@paginate.page%>" />
|
40
40
|
<input type="hidden" name="ex" value="<%=@exception%>" />
|
41
|
+
<input type="hidden" name="regex" value="<%=Rack::Utils.escape_html(@regex)%>" />
|
41
42
|
<select id="form_action" name="action">
|
42
43
|
<option id="default_option" value="" selected="selected">-- Select Action --</option>
|
43
44
|
<option value="clear">Clear</option>
|
data/test/dump.rdb
ADDED
Binary file
|
data/test/resque_cleaner_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
2
|
require 'time'
|
3
|
-
|
4
|
-
|
3
|
+
describe "ResqueCleaner" do
|
4
|
+
before do
|
5
5
|
Resque.redis.flushall
|
6
6
|
|
7
7
|
@worker = Resque::Worker.new(:jobs,:jobs2)
|
@@ -28,53 +28,53 @@ context "ResqueCleaner" do
|
|
28
28
|
@cleaner.print_message = false
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
it "#select_by_regex returns only Jason jobs" do
|
32
32
|
ret = @cleaner.select_by_regex(/Jason/)
|
33
33
|
assert_equal 13, ret.size
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
it "#select_by_regex returns an empty array if passed a non-regex" do
|
37
37
|
['string', nil, 13, Class.new].each do |non_regex|
|
38
38
|
ret = @cleaner.select_by_regex(nil)
|
39
39
|
assert_equal 0, ret.size
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
it "#select returns failure jobs" do
|
44
44
|
ret = @cleaner.select
|
45
45
|
assert_equal 42, ret.size
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
it "#select works with a limit" do
|
49
49
|
@cleaner.limiter.maximum = 10
|
50
50
|
ret = @cleaner.select
|
51
51
|
|
52
52
|
# only maximum number
|
53
53
|
assert_equal 10, ret.size
|
54
54
|
|
55
|
-
#
|
55
|
+
# lait one
|
56
56
|
assert_equal Time.parse(ret[0]['failed_at']), Time.parse('2010-08-13')
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
it "#select with a block returns failure jobs which the block evaluates true" do
|
60
60
|
ret = @cleaner.select {|job| job["payload"]["args"][0]=="Jason"}
|
61
61
|
assert_equal 13, ret.size
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
it "#clear deletes failure jobs" do
|
65
65
|
cleared = @cleaner.clear
|
66
66
|
assert_equal 42, cleared
|
67
67
|
assert_equal 0, @cleaner.select.size
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
it "#clear with a block deletes failure jobs which the block evaluates true" do
|
71
71
|
cleared = @cleaner.clear{|job| job["payload"]["args"][0]=="Jason"}
|
72
72
|
assert_equal 13, cleared
|
73
73
|
assert_equal 42-13, @cleaner.select.size
|
74
74
|
assert_equal 0, @cleaner.select{|job| job["payload"]["args"][0]=="Jason"}.size
|
75
75
|
end
|
76
76
|
|
77
|
-
|
77
|
+
it "#requeue retries failure jobs" do
|
78
78
|
assert_equal 0, queue_size(:jobs,:jobs2)
|
79
79
|
requeued = @cleaner.requeue
|
80
80
|
assert_equal 42, requeued
|
@@ -82,13 +82,13 @@ context "ResqueCleaner" do
|
|
82
82
|
assert_equal 42, queue_size(:jobs,:jobs2)
|
83
83
|
end
|
84
84
|
|
85
|
-
|
85
|
+
it "#requeue with a block retries failure jobs which the block evaluates true" do
|
86
86
|
requeued = @cleaner.requeue{|job| job["payload"]["args"][0]=="Jason"}
|
87
87
|
assert_equal 13, requeued
|
88
88
|
assert_equal 13, queue_size(:jobs,:jobs2)
|
89
89
|
end
|
90
90
|
|
91
|
-
|
91
|
+
it "#requeue with clear option requeues and deletes failure jobs" do
|
92
92
|
assert_equal 0, queue_size(:jobs,:jobs2)
|
93
93
|
requeued = @cleaner.requeue(true)
|
94
94
|
assert_equal 42, requeued
|
@@ -96,7 +96,7 @@ context "ResqueCleaner" do
|
|
96
96
|
assert_equal 0, @cleaner.select.size
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
it "#requeue with :queue option requeues the jobs to the queue" do
|
100
100
|
assert_equal 0, queue_size(:jobs,:jobs2,:retry)
|
101
101
|
requeued = @cleaner.requeue false, :queue => :retry
|
102
102
|
assert_equal 42, requeued
|
@@ -105,14 +105,14 @@ context "ResqueCleaner" do
|
|
105
105
|
assert_equal 42, queue_size(:retry)
|
106
106
|
end
|
107
107
|
|
108
|
-
|
108
|
+
it "#clear_stale deletes failure jobs which is queued before the last x enqueued" do
|
109
109
|
@cleaner.limiter.maximum = 10
|
110
110
|
@cleaner.clear_stale
|
111
111
|
assert_equal 10, @cleaner.failure.count
|
112
112
|
assert_equal Time.parse(@cleaner.failure_jobs[0]['failed_at']), Time.parse('2010-08-13')
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
it "FailedJobEx module extends job and provides some useful methods" do
|
116
116
|
# before 2009-04-01
|
117
117
|
ret = @cleaner.select {|j| j.before?('2009-04-01')}
|
118
118
|
assert_equal 6, ret.size
|
@@ -147,7 +147,7 @@ context "ResqueCleaner" do
|
|
147
147
|
assert_equal 1, ret.size
|
148
148
|
end
|
149
149
|
|
150
|
-
|
150
|
+
it "#stats_by_date returns stats grouped by date" do
|
151
151
|
ret = @cleaner.stats_by_date
|
152
152
|
assert_equal 6, ret['2009/03/13']
|
153
153
|
assert_equal 14, ret['2009/11/13']
|
@@ -159,25 +159,25 @@ context "ResqueCleaner" do
|
|
159
159
|
assert_equal 11, ret['2010/08/13']
|
160
160
|
end
|
161
161
|
|
162
|
-
|
162
|
+
it "#stats_by_class returns stats grouped by class" do
|
163
163
|
ret = @cleaner.stats_by_class
|
164
164
|
assert_equal 35, ret['BadJob']
|
165
165
|
assert_equal 7, ret['BadJobWithSyntaxError']
|
166
166
|
end
|
167
167
|
|
168
|
-
|
168
|
+
it "#stats_by_class works with broken log" do
|
169
169
|
add_empty_payload_failure
|
170
170
|
ret = @cleaner.stats_by_class
|
171
171
|
assert_equal 1, ret['UNKNOWN']
|
172
172
|
end
|
173
173
|
|
174
|
-
|
174
|
+
it "#stats_by_exception returns stats grouped by exception" do
|
175
175
|
ret = @cleaner.stats_by_exception
|
176
176
|
assert_equal 35, ret['RuntimeError']
|
177
177
|
assert_equal 7, ret['SyntaxError']
|
178
178
|
end
|
179
179
|
|
180
|
-
|
180
|
+
it "#lock ensures that a new failure job doesn't affect in a limit mode" do
|
181
181
|
@cleaner.limiter.maximum = 23
|
182
182
|
@cleaner.limiter.lock do
|
183
183
|
first = @cleaner.select[0]
|
@@ -192,9 +192,9 @@ context "ResqueCleaner" do
|
|
192
192
|
assert_equal "Jack", first["payload"]["args"][0]
|
193
193
|
end
|
194
194
|
|
195
|
-
|
195
|
+
it "allows you to configure limiter" do
|
196
196
|
c = Resque::Plugins::ResqueCleaner.new
|
197
|
-
|
197
|
+
refute_equal c.limiter.maximum, 10_000
|
198
198
|
|
199
199
|
module Resque::Plugins
|
200
200
|
ResqueCleaner::Limiter.default_maximum = 10_000
|
data/test/resque_web_test.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
2
|
|
3
|
-
# Pull in the server test_helper from resque
|
4
|
-
require 'resque/server/test_helper.rb'
|
5
3
|
require 'digest/sha1'
|
6
4
|
require 'json'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
class Minitest::Spec
|
8
|
+
include Rack::Test::Methods
|
9
|
+
def app
|
10
|
+
Resque::Server.new
|
11
|
+
end
|
12
|
+
end
|
7
13
|
|
8
14
|
def setup_some_failed_jobs
|
9
15
|
Resque.redis.flushall
|
@@ -20,39 +26,39 @@ def setup_some_failed_jobs
|
|
20
26
|
@cleaner.print_message = false
|
21
27
|
end
|
22
28
|
|
23
|
-
|
24
|
-
|
29
|
+
describe "resque-web" do
|
30
|
+
before do
|
25
31
|
setup_some_failed_jobs
|
26
32
|
end
|
27
33
|
|
28
|
-
|
34
|
+
it "#cleaner should respond with success" do
|
29
35
|
get "/cleaner"
|
30
36
|
assert last_response.body.include?('BadJob')
|
31
37
|
assert last_response.body =~ /\bException\b/
|
32
38
|
end
|
33
39
|
|
34
|
-
|
40
|
+
it "#cleaner_list should respond with success" do
|
35
41
|
get "/cleaner_list"
|
36
42
|
assert last_response.ok?, last_response.errors
|
37
43
|
end
|
38
44
|
|
39
|
-
|
45
|
+
it '#cleaner_list shows the failed jobs' do
|
40
46
|
get "/cleaner_list"
|
41
47
|
assert last_response.body.include?('BadJob')
|
42
48
|
end
|
43
49
|
|
44
|
-
|
50
|
+
it "#cleaner_list shows the failed jobs when we use a select_by_regex" do
|
45
51
|
get "/cleaner_list", :regex => "BadJob*"
|
46
52
|
assert last_response.body.include?('"BadJobWithSyntaxError"')
|
47
53
|
assert last_response.body.include?('"BadJob"')
|
48
54
|
end
|
49
55
|
|
50
56
|
|
51
|
-
|
57
|
+
it '#cleaner_exec clears job' do
|
52
58
|
post "/cleaner_exec", :action => "clear", :sha1 => Digest::SHA1.hexdigest(@cleaner.select[0].to_json)
|
53
59
|
assert_equal 10, @cleaner.select.size
|
54
60
|
end
|
55
|
-
|
61
|
+
it "#cleaner_dump should respond with success" do
|
56
62
|
get "/cleaner_dump"
|
57
63
|
assert last_response.ok?, last_response.errors
|
58
64
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,8 +4,10 @@
|
|
4
4
|
dir = File.dirname(File.expand_path(__FILE__))
|
5
5
|
$LOAD_PATH.unshift dir + '/../lib'
|
6
6
|
$TESTING = true
|
7
|
-
require 'test/unit'
|
8
7
|
require 'rubygems'
|
8
|
+
require 'minitest'
|
9
|
+
require 'minitest/spec'
|
10
|
+
require 'minitest/autorun'
|
9
11
|
require 'resque'
|
10
12
|
require 'timecop'
|
11
13
|
|
@@ -16,6 +18,8 @@ end
|
|
16
18
|
require 'resque'
|
17
19
|
require 'resque_cleaner'
|
18
20
|
|
21
|
+
$TEST_PID = Process.pid
|
22
|
+
|
19
23
|
#
|
20
24
|
# make sure we can run redis
|
21
25
|
#
|
@@ -31,48 +35,22 @@ end
|
|
31
35
|
# start our own redis when the tests start,
|
32
36
|
# kill it when they end
|
33
37
|
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
MiniTest.after_run {
|
39
|
+
if Process.pid == $TEST_PID
|
40
|
+
processes = `ps -A -o pid,command | grep [r]edis-test`.split($/)
|
41
|
+
pids = processes.map { |process| process.split(" ")[0] }
|
42
|
+
puts "Killing test redis server..."
|
43
|
+
pids.each { |pid| Process.kill("TERM", pid.to_i) }
|
44
|
+
dump = "test/dump.rdb"
|
45
|
+
File.delete(dump) if File.exist?(dump)
|
41
46
|
end
|
42
|
-
|
43
|
-
pid = `ps -A -o pid,command | grep [r]edis-test`.split(" ")[0]
|
44
|
-
puts "Killing test redis server..."
|
45
|
-
Process.kill("KILL", pid.to_i)
|
46
|
-
dump = "test/dump.rdb"
|
47
|
-
File.delete(dump) if File.exist?(dump)
|
48
|
-
exit exit_code
|
49
|
-
end
|
47
|
+
}
|
50
48
|
|
51
49
|
puts "Starting redis for testing at localhost:9736..."
|
52
50
|
`redis-server #{dir}/redis-test.conf`
|
53
51
|
Resque.redis = 'localhost:9736'
|
54
52
|
|
55
53
|
|
56
|
-
##
|
57
|
-
# test/spec/mini 3
|
58
|
-
# http://gist.github.com/25455
|
59
|
-
# chris@ozmm.org
|
60
|
-
#
|
61
|
-
def context(*args, &block)
|
62
|
-
return super unless (name = args.first) && block
|
63
|
-
require 'test/unit'
|
64
|
-
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
|
65
|
-
def self.test(name, &block)
|
66
|
-
define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
|
67
|
-
end
|
68
|
-
def self.xtest(*args) end
|
69
|
-
def self.setup(&block) define_method(:setup, &block) end
|
70
|
-
def self.teardown(&block) define_method(:teardown, &block) end
|
71
|
-
end
|
72
|
-
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
|
73
|
-
klass.class_eval &block
|
74
|
-
end
|
75
|
-
|
76
54
|
##
|
77
55
|
# Helper to perform job classes
|
78
56
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuya Ono
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resque
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.6.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.6.0
|
27
55
|
description: ! ' resque-cleaner maintains the cleanliness of failed jobs on Resque.
|
28
56
|
|
29
57
|
'
|
@@ -49,6 +77,7 @@ files:
|
|
49
77
|
- lib/resque_cleaner/server/views/cleaner_list.erb
|
50
78
|
- lib/resque_cleaner/server.rb
|
51
79
|
- lib/resque_cleaner.rb
|
80
|
+
- test/dump.rdb
|
52
81
|
- test/redis-test.conf
|
53
82
|
- test/resque_cleaner_test.rb
|
54
83
|
- test/resque_web_test.rb
|