sidekiq 2.5.4 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- data/.travis.yml +2 -0
- data/Changes.md +10 -0
- data/examples/sinkiq.rb +3 -2
- data/lib/sidekiq/api.rb +135 -6
- data/lib/sidekiq/capistrano.rb +5 -3
- data/lib/sidekiq/cli.rb +23 -6
- data/lib/sidekiq/logging.rb +8 -7
- data/lib/sidekiq/processor.rb +2 -0
- data/lib/sidekiq/stats.rb +1 -24
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web.rb +63 -79
- data/test/config.yml +1 -0
- data/test/test_api.rb +189 -5
- data/test/test_cli.rb +46 -0
- data/test/test_processor.rb +53 -0
- data/test/test_sidekiq.rb +14 -0
- data/test/test_stats.rb +0 -60
- data/test/test_web.rb +63 -53
- data/web/assets/javascripts/application.js +24 -66
- data/web/assets/javascripts/dashboard.js +110 -0
- data/web/assets/stylesheets/application.css +402 -258
- data/web/assets/stylesheets/bootstrap.css +1 -1
- data/web/views/_nav.slim +8 -13
- data/web/views/_summary.slim +6 -6
- data/web/views/dashboard.slim +36 -0
- data/web/views/layout.slim +22 -21
- data/web/views/queue.slim +3 -3
- data/web/views/queues.slim +13 -17
- data/web/views/retries.slim +3 -3
- data/web/views/retry.slim +46 -43
- data/web/views/scheduled.slim +2 -2
- metadata +6 -6
- data/web/assets/javascripts/vendor/bootstrap.js +0 -7
- data/web/assets/javascripts/vendor/jquery.js +0 -3
- data/web/assets/javascripts/vendor/jquery.timeago.js +0 -148
- data/web/views/poll.slim +0 -4
data/test/config.yml
CHANGED
data/test/test_api.rb
CHANGED
@@ -1,6 +1,149 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestApi < MiniTest::Unit::TestCase
|
4
|
+
describe "stats" do
|
5
|
+
before do
|
6
|
+
Sidekiq.redis {|c| c.flushdb }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "processed" do
|
10
|
+
it "is initially zero" do
|
11
|
+
s = Sidekiq::Stats.new
|
12
|
+
assert_equal 0, s.processed
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns number of processed jobs" do
|
16
|
+
Sidekiq.redis { |conn| conn.set("stat:processed", 5) }
|
17
|
+
s = Sidekiq::Stats.new
|
18
|
+
assert_equal 5, s.processed
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "failed" do
|
23
|
+
it "is initially zero" do
|
24
|
+
s = Sidekiq::Stats.new
|
25
|
+
assert_equal 0, s.processed
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns number of failed jobs" do
|
29
|
+
Sidekiq.redis { |conn| conn.set("stat:failed", 5) }
|
30
|
+
s = Sidekiq::Stats.new
|
31
|
+
assert_equal 5, s.failed
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "queues" do
|
36
|
+
it "is initially empty" do
|
37
|
+
s = Sidekiq::Stats.new
|
38
|
+
assert_equal 0, s.queues.size
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns a hash of queue and size in order" do
|
42
|
+
Sidekiq.redis do |conn|
|
43
|
+
conn.rpush 'queue:foo', '{}'
|
44
|
+
conn.sadd 'queues', 'foo'
|
45
|
+
|
46
|
+
3.times { conn.rpush 'queue:bar', '{}' }
|
47
|
+
conn.sadd 'queues', 'bar'
|
48
|
+
end
|
49
|
+
|
50
|
+
s = Sidekiq::Stats.new
|
51
|
+
assert_equal ({ "foo" => 1, "bar" => 3 }), s.queues
|
52
|
+
assert_equal "bar", s.queues.first.first
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "enqueued" do
|
57
|
+
it "is initially empty" do
|
58
|
+
s = Sidekiq::Stats.new
|
59
|
+
assert_equal 0, s.enqueued
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns total enqueued jobs" do
|
63
|
+
Sidekiq.redis do |conn|
|
64
|
+
conn.rpush 'queue:foo', '{}'
|
65
|
+
conn.sadd 'queues', 'foo'
|
66
|
+
|
67
|
+
3.times { conn.rpush 'queue:bar', '{}' }
|
68
|
+
conn.sadd 'queues', 'bar'
|
69
|
+
end
|
70
|
+
|
71
|
+
s = Sidekiq::Stats.new
|
72
|
+
assert_equal 4, s.enqueued
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "over time" do
|
77
|
+
describe "processed" do
|
78
|
+
it 'retrieves hash of dates' do
|
79
|
+
Sidekiq.redis do |c|
|
80
|
+
c.incrby("stat:processed:2012-12-24", 4)
|
81
|
+
c.incrby("stat:processed:2012-12-25", 1)
|
82
|
+
c.incrby("stat:processed:2012-12-26", 6)
|
83
|
+
c.incrby("stat:processed:2012-12-27", 2)
|
84
|
+
end
|
85
|
+
Time.stub(:now, Time.parse("2012-12-26 1:00:00 -0500")) do
|
86
|
+
s = Sidekiq::Stats::History.new(2)
|
87
|
+
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1 }), s.processed
|
88
|
+
|
89
|
+
s = Sidekiq::Stats::History.new(3)
|
90
|
+
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1, "2012-12-24" => 4 }), s.processed
|
91
|
+
|
92
|
+
s = Sidekiq::Stats::History.new(2, Date.parse("2012-12-25"))
|
93
|
+
assert_equal ({ "2012-12-25" => 1, "2012-12-24" => 4 }), s.processed
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "failed" do
|
99
|
+
it 'retrieves hash of dates' do
|
100
|
+
Sidekiq.redis do |c|
|
101
|
+
c.incrby("stat:failed:2012-12-24", 4)
|
102
|
+
c.incrby("stat:failed:2012-12-25", 1)
|
103
|
+
c.incrby("stat:failed:2012-12-26", 6)
|
104
|
+
c.incrby("stat:failed:2012-12-27", 2)
|
105
|
+
end
|
106
|
+
Time.stub(:now, Time.parse("2012-12-26 1:00:00 -0500")) do
|
107
|
+
s = Sidekiq::Stats::History.new(2)
|
108
|
+
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1 }), s.failed
|
109
|
+
|
110
|
+
s = Sidekiq::Stats::History.new(3)
|
111
|
+
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1, "2012-12-24" => 4 }), s.failed
|
112
|
+
|
113
|
+
s = Sidekiq::Stats::History.new(2, Date.parse("2012-12-25"))
|
114
|
+
assert_equal ({ "2012-12-25" => 1, "2012-12-24" => 4 }), s.failed
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "cleanup" do
|
120
|
+
it 'removes processed stats outside of keep window' do
|
121
|
+
Sidekiq.redis do |c|
|
122
|
+
c.incrby("stat:processed:2012-05-03", 4)
|
123
|
+
c.incrby("stat:processed:2012-06-03", 4)
|
124
|
+
c.incrby("stat:processed:2012-07-03", 1)
|
125
|
+
end
|
126
|
+
Time.stub(:now, Time.parse("2012-12-01 1:00:00 -0500")) do
|
127
|
+
Sidekiq::Stats::History.cleanup
|
128
|
+
assert_equal false, Sidekiq.redis { |c| c.exists("stat:processed:2012-05-03") }
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'removes failed stats outside of keep window' do
|
133
|
+
Sidekiq.redis do |c|
|
134
|
+
c.incrby("stat:failed:2012-05-03", 4)
|
135
|
+
c.incrby("stat:failed:2012-06-03", 4)
|
136
|
+
c.incrby("stat:failed:2012-07-03", 1)
|
137
|
+
end
|
138
|
+
Time.stub(:now, Time.parse("2012-12-01 1:00:00 -0500")) do
|
139
|
+
Sidekiq::Stats::History.cleanup
|
140
|
+
assert_equal false, Sidekiq.redis { |c| c.exists("stat:failed:2012-05-03") }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
4
147
|
describe 'with an empty database' do
|
5
148
|
before do
|
6
149
|
Sidekiq.redis {|c| c.flushdb }
|
@@ -47,6 +190,24 @@ class TestApi < MiniTest::Unit::TestCase
|
|
47
190
|
end
|
48
191
|
end
|
49
192
|
|
193
|
+
it 'can fetch by score' do
|
194
|
+
same_time = Time.now.to_f
|
195
|
+
add_retry('bob1', same_time)
|
196
|
+
add_retry('bob2', same_time)
|
197
|
+
r = Sidekiq::RetrySet.new
|
198
|
+
assert_equal 2, r.fetch(same_time).size
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'can fetch by score and jid' do
|
202
|
+
same_time = Time.now.to_f
|
203
|
+
add_retry('bob1', same_time)
|
204
|
+
add_retry('bob2', same_time)
|
205
|
+
r = Sidekiq::RetrySet.new
|
206
|
+
# jobs = r.fetch(same_time)
|
207
|
+
# puts jobs[1].jid
|
208
|
+
assert_equal 1, r.fetch(same_time, 'bob1').size
|
209
|
+
end
|
210
|
+
|
50
211
|
it 'shows empty retries' do
|
51
212
|
r = Sidekiq::RetrySet.new
|
52
213
|
assert_equal 0, r.size
|
@@ -67,12 +228,36 @@ class TestApi < MiniTest::Unit::TestCase
|
|
67
228
|
assert_in_delta Time.now.to_f, retri.at.to_f, 0.01
|
68
229
|
end
|
69
230
|
|
70
|
-
it 'can delete retries' do
|
231
|
+
it 'can delete multiple retries from score' do
|
232
|
+
same_time = Time.now.to_f
|
233
|
+
add_retry('bob1', same_time)
|
234
|
+
add_retry('bob2', same_time)
|
235
|
+
r = Sidekiq::RetrySet.new
|
236
|
+
assert_equal 2, r.size
|
237
|
+
Sidekiq::RetrySet.new.delete(same_time)
|
238
|
+
assert_equal 0, r.size
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'can delete a single retry from score and jid' do
|
242
|
+
same_time = Time.now.to_f
|
243
|
+
add_retry('bob1', same_time)
|
244
|
+
add_retry('bob2', same_time)
|
245
|
+
r = Sidekiq::RetrySet.new
|
246
|
+
assert_equal 2, r.size
|
247
|
+
Sidekiq::RetrySet.new.delete(same_time, 'bob1')
|
248
|
+
assert_equal 1, r.size
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'can retry a retry' do
|
71
252
|
add_retry
|
72
253
|
r = Sidekiq::RetrySet.new
|
73
254
|
assert_equal 1, r.size
|
74
|
-
r.
|
255
|
+
r.first.retry
|
75
256
|
assert_equal 0, r.size
|
257
|
+
assert_equal 1, Sidekiq::Queue.new('default').size
|
258
|
+
job = Sidekiq::Queue.new('default').first
|
259
|
+
assert_equal 'bob', job.jid
|
260
|
+
assert_equal 1, job['retry_count']
|
76
261
|
end
|
77
262
|
|
78
263
|
it 'can clear retries' do
|
@@ -84,9 +269,8 @@ class TestApi < MiniTest::Unit::TestCase
|
|
84
269
|
assert_equal 0, r.size
|
85
270
|
end
|
86
271
|
|
87
|
-
def add_retry(jid = 'bob')
|
88
|
-
|
89
|
-
payload = Sidekiq.dump_json('class' => 'ApiWorker', 'args' => [1, 'mike'], 'queue' => 'default', 'jid' => jid)
|
272
|
+
def add_retry(jid = 'bob', at = Time.now.to_f)
|
273
|
+
payload = Sidekiq.dump_json('class' => 'ApiWorker', 'args' => [1, 'mike'], 'queue' => 'default', 'jid' => jid, 'retry_count' => 2, 'failed_at' => Time.now.utc)
|
90
274
|
Sidekiq.redis do |conn|
|
91
275
|
conn.zadd('retry', at.to_s, payload)
|
92
276
|
end
|
data/test/test_cli.rb
CHANGED
@@ -80,9 +80,51 @@ class TestCli < MiniTest::Unit::TestCase
|
|
80
80
|
@cli.parse(['sidekiq', '-v', '-r', './test/fake_env.rb'])
|
81
81
|
assert_equal Logger::DEBUG, Sidekiq.logger.level
|
82
82
|
# If we leave the logger at DEBUG it'll add a lot of noise to the test output
|
83
|
+
Sidekiq.options.delete(:verbose)
|
83
84
|
Sidekiq.logger.level = old
|
84
85
|
end
|
85
86
|
|
87
|
+
describe 'with logfile' do
|
88
|
+
before do
|
89
|
+
@old_logger = Sidekiq.logger
|
90
|
+
@tmp_log_path = '/tmp/sidekiq.log'
|
91
|
+
end
|
92
|
+
|
93
|
+
after do
|
94
|
+
Sidekiq.logger = @old_logger
|
95
|
+
Sidekiq.options.delete(:logfile)
|
96
|
+
File.unlink @tmp_log_path if File.exists?(@tmp_log_path)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'sets the logfile path' do
|
100
|
+
@cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
|
101
|
+
|
102
|
+
assert_equal @tmp_log_path, Sidekiq.options[:logfile]
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'creates and writes to a logfile' do
|
106
|
+
@cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
|
107
|
+
|
108
|
+
Sidekiq.logger.info('test message')
|
109
|
+
|
110
|
+
assert_match /test message/, File.read(@tmp_log_path), "didn't include the log message"
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'appends messages to a logfile' do
|
114
|
+
File.open(@tmp_log_path, 'w') do |f|
|
115
|
+
f.puts 'already existant log message'
|
116
|
+
end
|
117
|
+
|
118
|
+
@cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
|
119
|
+
|
120
|
+
Sidekiq.logger.info('test message')
|
121
|
+
|
122
|
+
log_file_content = File.read(@tmp_log_path)
|
123
|
+
assert_match /already existant/, log_file_content, "didn't include the old message"
|
124
|
+
assert_match /test message/, log_file_content, "didn't include the new message"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
86
128
|
describe 'with pidfile' do
|
87
129
|
before do
|
88
130
|
@tmp_file = Tempfile.new('sidekiq-test')
|
@@ -134,6 +176,10 @@ class TestCli < MiniTest::Unit::TestCase
|
|
134
176
|
assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
|
135
177
|
end
|
136
178
|
|
179
|
+
it 'sets logfile' do
|
180
|
+
assert_equal '/tmp/sidekiq.log', Sidekiq.options[:logfile]
|
181
|
+
end
|
182
|
+
|
137
183
|
it 'sets queues' do
|
138
184
|
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
139
185
|
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
data/test/test_processor.rb
CHANGED
@@ -67,5 +67,58 @@ class TestProcessor < MiniTest::Unit::TestCase
|
|
67
67
|
processor.process(msgstr, 'default')
|
68
68
|
assert_equal [['myarg']], msg['args']
|
69
69
|
end
|
70
|
+
|
71
|
+
describe 'stats' do
|
72
|
+
before do
|
73
|
+
Sidekiq.redis {|c| c.flushdb }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'when successful' do
|
77
|
+
def successful_job
|
78
|
+
msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['myarg'] })
|
79
|
+
actor = MiniTest::Mock.new
|
80
|
+
actor.expect(:processor_done, nil, [@processor])
|
81
|
+
@boss.expect(:async, actor, [])
|
82
|
+
@processor.process(msg, 'default')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'increments processed stat' do
|
86
|
+
successful_job
|
87
|
+
assert_equal 1, Sidekiq::Stats.new.processed
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'increments date processed stat' do
|
91
|
+
Time.stub(:now, Time.parse("2012-12-25 1:00:00 -0500")) do
|
92
|
+
successful_job
|
93
|
+
date_processed = Sidekiq.redis { |conn| conn.get("stat:processed:2012-12-25") }.to_i
|
94
|
+
assert_equal 1, date_processed
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'when failed' do
|
100
|
+
def failed_job
|
101
|
+
msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['boom'] })
|
102
|
+
begin
|
103
|
+
@processor.process(msg, 'default')
|
104
|
+
rescue TestException
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'increments failed stat' do
|
109
|
+
failed_job
|
110
|
+
assert_equal 1, Sidekiq::Stats.new.failed
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'increments date failed stat' do
|
114
|
+
Time.stub(:now, Time.parse("2012-12-25 1:00:00 -0500")) do
|
115
|
+
failed_job
|
116
|
+
date_failed = Sidekiq.redis { |conn| conn.get("stat:failed:2012-12-25") }.to_i
|
117
|
+
assert_equal 1, date_failed
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
70
123
|
end
|
71
124
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSidekiq < MiniTest::Unit::TestCase
|
4
|
+
describe 'json processing' do
|
5
|
+
it 'loads json' do
|
6
|
+
assert_equal ({"foo" => "bar"}), Sidekiq.load_json("{\"foo\":\"bar\"}")
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'dumps json' do
|
10
|
+
assert_equal "{\"foo\":\"bar\"}", Sidekiq.dump_json({ "foo" => "bar" })
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/test/test_stats.rb
CHANGED
@@ -18,54 +18,6 @@ class TestStats < MiniTest::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
it 'updates global stats in the success case' do
|
22
|
-
msg = Sidekiq.dump_json({ 'class' => DumbWorker.to_s, 'args' => [""] })
|
23
|
-
boss = MiniTest::Mock.new
|
24
|
-
actor = MiniTest::Mock.new
|
25
|
-
|
26
|
-
@redis.with do |conn|
|
27
|
-
|
28
|
-
set = conn.smembers('workers')
|
29
|
-
assert_equal 0, set.size
|
30
|
-
|
31
|
-
processor = Sidekiq::Processor.new(boss)
|
32
|
-
3.times do
|
33
|
-
actor.expect(:processor_done, nil, [processor])
|
34
|
-
boss.expect(:async, actor, [])
|
35
|
-
end
|
36
|
-
|
37
|
-
assert_equal 0, Sidekiq.info[:failed]
|
38
|
-
assert_equal 0, Sidekiq.info[:processed]
|
39
|
-
|
40
|
-
processor.process(msg, 'xyzzy')
|
41
|
-
processor.process(msg, 'xyzzy')
|
42
|
-
processor.process(msg, 'xyzzy')
|
43
|
-
|
44
|
-
assert_equal 0, Sidekiq.info[:failed]
|
45
|
-
assert_equal 3, Sidekiq.info[:processed]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'updates global stats in the error case' do
|
50
|
-
msg = Sidekiq.dump_json({ 'class' => DumbWorker.to_s, 'args' => [nil] })
|
51
|
-
boss = MiniTest::Mock.new
|
52
|
-
|
53
|
-
@redis.with do |conn|
|
54
|
-
assert_equal [], conn.smembers('workers')
|
55
|
-
assert_equal 0, Sidekiq.info[:failed]
|
56
|
-
assert_equal 0, Sidekiq.info[:processed]
|
57
|
-
|
58
|
-
processor = Sidekiq::Processor.new(boss)
|
59
|
-
|
60
|
-
assert_raises RuntimeError do
|
61
|
-
processor.process(msg, 'xyzzy')
|
62
|
-
end
|
63
|
-
|
64
|
-
assert_equal 1, Sidekiq.info[:failed]
|
65
|
-
assert_equal 1, Sidekiq.info[:processed]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
21
|
describe "info counts" do
|
70
22
|
before do
|
71
23
|
@redis.with do |conn|
|
@@ -80,18 +32,6 @@ class TestStats < MiniTest::Unit::TestCase
|
|
80
32
|
end
|
81
33
|
end
|
82
34
|
|
83
|
-
describe "queues_with_sizes" do
|
84
|
-
it "returns queue names and corresponding job counts" do
|
85
|
-
assert_equal [["foo", 1], ["baz", 2], ["bar", 3]], Sidekiq.info[:queues_with_sizes]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "backlog" do
|
90
|
-
it "returns count of all jobs yet to be processed" do
|
91
|
-
assert_equal 6, Sidekiq.info[:backlog]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
35
|
describe "size" do
|
96
36
|
it "returns size of queues" do
|
97
37
|
assert_equal 0, Sidekiq.size("foox")
|
data/test/test_web.rb
CHANGED
@@ -11,6 +11,10 @@ class TestWeb < MiniTest::Unit::TestCase
|
|
11
11
|
Sidekiq::Web
|
12
12
|
end
|
13
13
|
|
14
|
+
def job_params(job, score)
|
15
|
+
"#{score}-#{job['jid']}"
|
16
|
+
end
|
17
|
+
|
14
18
|
before do
|
15
19
|
Sidekiq.redis = REDIS
|
16
20
|
Sidekiq.redis {|c| c.flushdb }
|
@@ -31,14 +35,6 @@ class TestWeb < MiniTest::Unit::TestCase
|
|
31
35
|
refute_match /default/, last_response.body
|
32
36
|
end
|
33
37
|
|
34
|
-
it 'can display poll' do
|
35
|
-
get '/poll'
|
36
|
-
assert_equal 200, last_response.status
|
37
|
-
assert_match /summary/, last_response.body
|
38
|
-
assert_match /workers/, last_response.body
|
39
|
-
refute_match /navbar/, last_response.body
|
40
|
-
end
|
41
|
-
|
42
38
|
it 'can display queues' do
|
43
39
|
assert Sidekiq::Client.push('queue' => :foo, 'class' => WebWorker, 'args' => [1, 3])
|
44
40
|
|
@@ -48,11 +44,6 @@ class TestWeb < MiniTest::Unit::TestCase
|
|
48
44
|
refute_match /HardWorker/, last_response.body
|
49
45
|
end
|
50
46
|
|
51
|
-
it 'handles missing retry' do
|
52
|
-
get '/retries/12391982.123'
|
53
|
-
assert_equal 302, last_response.status
|
54
|
-
end
|
55
|
-
|
56
47
|
it 'handles queue view' do
|
57
48
|
get '/queues/default'
|
58
49
|
assert_equal 200, last_response.status
|
@@ -94,31 +85,6 @@ class TestWeb < MiniTest::Unit::TestCase
|
|
94
85
|
end
|
95
86
|
end
|
96
87
|
|
97
|
-
it 'can display scheduled' do
|
98
|
-
get '/scheduled'
|
99
|
-
assert_equal 200, last_response.status
|
100
|
-
assert_match /found/, last_response.body
|
101
|
-
refute_match /HardWorker/, last_response.body
|
102
|
-
|
103
|
-
add_scheduled
|
104
|
-
|
105
|
-
get '/scheduled'
|
106
|
-
assert_equal 200, last_response.status
|
107
|
-
refute_match /found/, last_response.body
|
108
|
-
assert_match /HardWorker/, last_response.body
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'can delete scheduled' do
|
112
|
-
msg,score = add_scheduled
|
113
|
-
Sidekiq.redis do |conn|
|
114
|
-
assert_equal 1, conn.zcard('schedule')
|
115
|
-
post '/scheduled', 'score' => [score], 'delete' => 'Delete'
|
116
|
-
assert_equal 302, last_response.status
|
117
|
-
assert_equal 'http://example.org/scheduled', last_response.header['Location']
|
118
|
-
assert_equal 0, conn.zcard('schedule')
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
88
|
it 'can display retries' do
|
123
89
|
get '/retries'
|
124
90
|
assert_equal 200, last_response.status
|
@@ -134,25 +100,28 @@ class TestWeb < MiniTest::Unit::TestCase
|
|
134
100
|
end
|
135
101
|
|
136
102
|
it 'can display a single retry' do
|
137
|
-
|
103
|
+
params = add_retry
|
104
|
+
get '/retries/2c4c17969825a384a92f023b'
|
138
105
|
assert_equal 302, last_response.status
|
139
|
-
|
140
|
-
|
141
|
-
get "/retries/#{score}"
|
106
|
+
get "/retries/#{job_params(*params)}"
|
142
107
|
assert_equal 200, last_response.status
|
143
108
|
assert_match /HardWorker/, last_response.body
|
144
109
|
end
|
145
110
|
|
146
|
-
it '
|
147
|
-
|
111
|
+
it 'handles missing retry' do
|
112
|
+
get "/retries/2c4c17969825a384a92f023b"
|
113
|
+
assert_equal 302, last_response.status
|
114
|
+
end
|
148
115
|
|
149
|
-
|
116
|
+
it 'can delete a single retry' do
|
117
|
+
params = add_retry
|
118
|
+
post "/retries/#{job_params(*params)}", 'delete' => 'Delete'
|
150
119
|
assert_equal 302, last_response.status
|
151
120
|
assert_equal 'http://example.org/retries', last_response.header['Location']
|
152
121
|
|
153
122
|
get "/retries"
|
154
123
|
assert_equal 200, last_response.status
|
155
|
-
refute_match /#{
|
124
|
+
refute_match /#{params.first['args'][2]}/, last_response.body
|
156
125
|
end
|
157
126
|
|
158
127
|
it 'can delete all retries' do
|
@@ -165,15 +134,39 @@ class TestWeb < MiniTest::Unit::TestCase
|
|
165
134
|
end
|
166
135
|
|
167
136
|
it 'can retry a single retry now' do
|
168
|
-
|
169
|
-
|
170
|
-
post "/retries/#{score}", 'retry' => 'Retry'
|
137
|
+
params = add_retry
|
138
|
+
post "/retries/#{job_params(*params)}", 'retry' => 'Retry'
|
171
139
|
assert_equal 302, last_response.status
|
172
140
|
assert_equal 'http://example.org/retries', last_response.header['Location']
|
173
141
|
|
174
142
|
get '/queues/default'
|
175
143
|
assert_equal 200, last_response.status
|
176
|
-
assert_match /#{
|
144
|
+
assert_match /#{params.first['args'][2]}/, last_response.body
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'can display scheduled' do
|
148
|
+
get '/scheduled'
|
149
|
+
assert_equal 200, last_response.status
|
150
|
+
assert_match /found/, last_response.body
|
151
|
+
refute_match /HardWorker/, last_response.body
|
152
|
+
|
153
|
+
add_scheduled
|
154
|
+
|
155
|
+
get '/scheduled'
|
156
|
+
assert_equal 200, last_response.status
|
157
|
+
refute_match /found/, last_response.body
|
158
|
+
assert_match /HardWorker/, last_response.body
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'can delete scheduled' do
|
162
|
+
params = add_scheduled
|
163
|
+
Sidekiq.redis do |conn|
|
164
|
+
assert_equal 1, conn.zcard('schedule')
|
165
|
+
post '/scheduled', 'key' => [job_params(*params)], 'delete' => 'Delete'
|
166
|
+
assert_equal 302, last_response.status
|
167
|
+
assert_equal 'http://example.org/scheduled', last_response.header['Location']
|
168
|
+
assert_equal 0, conn.zcard('schedule')
|
169
|
+
end
|
177
170
|
end
|
178
171
|
|
179
172
|
it 'can retry all retries' do
|
@@ -202,11 +195,27 @@ class TestWeb < MiniTest::Unit::TestCase
|
|
202
195
|
end
|
203
196
|
end
|
204
197
|
|
198
|
+
it 'can display the dashboard' do
|
199
|
+
get '/dashboard'
|
200
|
+
assert_equal 200, last_response.status
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'can refresh dashboard stats' do
|
204
|
+
Sidekiq.redis do |conn|
|
205
|
+
conn.set("stat:processed", 5)
|
206
|
+
conn.set("stat:failed", 2)
|
207
|
+
end
|
208
|
+
get '/dashboard/stats'
|
209
|
+
assert_equal 200, last_response.status
|
210
|
+
assert_equal "{\"processed\":5,\"failed\":2}", last_response.body
|
211
|
+
end
|
212
|
+
|
205
213
|
def add_scheduled
|
214
|
+
score = Time.now.to_f
|
206
215
|
msg = { 'class' => 'HardWorker',
|
207
216
|
'args' => ['bob', 1, Time.now.to_f],
|
208
|
-
'at' =>
|
209
|
-
|
217
|
+
'at' => score,
|
218
|
+
'jid' => 'f39af2a05e8f4b24dbc0f1e4' }
|
210
219
|
Sidekiq.redis do |conn|
|
211
220
|
conn.zadd('schedule', score, Sidekiq.dump_json(msg))
|
212
221
|
end
|
@@ -220,7 +229,8 @@ class TestWeb < MiniTest::Unit::TestCase
|
|
220
229
|
'error_message' => 'Some fake message',
|
221
230
|
'error_class' => 'RuntimeError',
|
222
231
|
'retry_count' => 0,
|
223
|
-
'failed_at' => Time.now.utc,
|
232
|
+
'failed_at' => Time.now.utc,
|
233
|
+
'jid' => 'f39af2a05e8f4b24dbc0f1e4'}
|
224
234
|
score = Time.now.to_f
|
225
235
|
Sidekiq.redis do |conn|
|
226
236
|
conn.zadd('retry', score, Sidekiq.dump_json(msg))
|