resque_stuck_queue 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +3 -2
- data/lib/resque_stuck_queue.rb +9 -3
- data/lib/resque_stuck_queue/version.rb +1 -1
- data/test/resque/set_redis_key.rb +2 -1
- data/test/test_collision.rb +9 -8
- data/test/test_integration.rb +9 -6
- data/test/test_named_queues.rb +6 -4
- data/test/test_resque_2.rb +3 -2
- data/test/test_resque_stuck_queue.rb +4 -3
- data/test/test_set_custom_refresh_job.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA1:
|
3
|
-
data.tar.gz: 984e71835c73d5f071caca892a28cb91ac6efb8f
|
4
|
-
metadata.gz: 0f1326d639f3e02c6710b18bb4ba16f25edd30f9
|
5
2
|
SHA512:
|
6
|
-
|
7
|
-
|
3
|
+
metadata.gz: df4e25ba257df91726f7c92cfe1a92f1a04b2afecb0106a4a80d0da12b494c67672fd5c40a981c813b4e18ede7d18b5e2aba3c8a445692e910acc17b9adc360e
|
4
|
+
data.tar.gz: 22f4307be4f19c7e3b138c4d18013ac8fefc3a7a4d53a4071c6a6f8c1f32ec9dce2f187db9476e12d4f871a332ba6d9842fd6eb6d2ac6bf576dad79522eae783
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: ff579897e68c118a67fe037962f318c2a265e851
|
7
|
+
data.tar.gz: a82bad8bbf4ce498aac49d8b1f54c42047ee6b15
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ Resque::StuckQueue.config[:trigger_timeout] = 10.hours
|
|
36
36
|
#
|
37
37
|
# triggering will update the key, so you'll have to wait the trigger_timeout again
|
38
38
|
# in order for it to trigger again even if workers are still stale.
|
39
|
-
Resque::StuckQueue.config[:handler] = proc { send_email }
|
39
|
+
Resque::StuckQueue.config[:handler] = proc { |queue_name| send_email("queue #{queue_name} isnt working, aaah the daemons") }
|
40
40
|
|
41
41
|
# optional, in case you want to set your own name for the key that will be used as the last good hearbeat time
|
42
42
|
# note this will be namespaced under the specific queue it's monitoring, for eg "app:name-the-refresh-key-as-you-please"
|
@@ -94,7 +94,7 @@ namespace :resque do
|
|
94
94
|
|
95
95
|
Resque::StuckQueue.config[:heartbeat] = 10.minutes
|
96
96
|
Resque::StuckQueue.config[:trigger_timeout] = 1.hour
|
97
|
-
Resque::StuckQueue.config[:handler] = proc { $stderr.puts("resque wonky!") }
|
97
|
+
Resque::StuckQueue.config[:handler] = proc { |queue_name| $stderr.puts("resque queue #{queue_name} wonky!") }
|
98
98
|
|
99
99
|
Resque::StuckQueue.start # blocking operation, daemon running
|
100
100
|
end
|
@@ -133,3 +133,4 @@ Resque::StuckQueue.config[:refresh_job] = proc {
|
|
133
133
|
Run the tests:
|
134
134
|
|
135
135
|
`bundle; bundle exec rake`
|
136
|
+
`RESQUE_2=1 bundle exec rake # for resq 2 compat`
|
data/lib/resque_stuck_queue.rb
CHANGED
@@ -14,7 +14,7 @@ module Resque
|
|
14
14
|
GLOBAL_KEY = "resque-stuck-queue"
|
15
15
|
HEARTBEAT = 60 * 60 # check/refresh every hour
|
16
16
|
TRIGGER_TIMEOUT = 5 * 60 * 60 # warn/trigger 5 hours
|
17
|
-
HANDLER = proc { $stdout.puts("Shit gone bad with them queues.") }
|
17
|
+
HANDLER = proc { |queue_name| $stdout.puts("Shit gone bad with them queues...on #{queue_name}.") }
|
18
18
|
|
19
19
|
class << self
|
20
20
|
|
@@ -34,7 +34,7 @@ module Resque
|
|
34
34
|
# :abort_on_exception
|
35
35
|
#
|
36
36
|
# # default handler
|
37
|
-
# config[:handler] = proc { send_mail }
|
37
|
+
# config[:handler] = proc { |queue_name| send_mail }
|
38
38
|
#
|
39
39
|
# # explicit redis
|
40
40
|
# config[:redis] = Redis.new
|
@@ -50,6 +50,12 @@ module Resque
|
|
50
50
|
@redis ||= (config[:redis] || Resque.redis)
|
51
51
|
end
|
52
52
|
|
53
|
+
def redis=(rds)
|
54
|
+
# for resq2 tests
|
55
|
+
@redis = rds
|
56
|
+
Resque.redis = @redis
|
57
|
+
end
|
58
|
+
|
53
59
|
def global_key_for(under_queue)
|
54
60
|
"#{under_queue}:#{config[:global_key] || GLOBAL_KEY}"
|
55
61
|
end
|
@@ -181,7 +187,7 @@ module Resque
|
|
181
187
|
end
|
182
188
|
|
183
189
|
def trigger_handler(queue_name)
|
184
|
-
(config[:handler] || HANDLER).call
|
190
|
+
(config[:handler] || HANDLER).call(queue_name)
|
185
191
|
manual_refresh(queue_name)
|
186
192
|
rescue => e
|
187
193
|
logger.info("handler for #{queue_name} crashed: #{e.inspect}")
|
data/test/test_collision.rb
CHANGED
@@ -5,18 +5,19 @@ class TestCollision < Minitest::Test
|
|
5
5
|
include TestHelper
|
6
6
|
|
7
7
|
def setup
|
8
|
-
Resque.redis.
|
8
|
+
Resque::StuckQueue.redis = Redis.new
|
9
|
+
Resque::StuckQueue.redis.flushall
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_two_processes_interacting
|
12
13
|
puts "#{__method__}"
|
13
14
|
# no resque should be running here so timeouts will be reached + trigger
|
14
|
-
Resque.redis.del("test-incr-key")
|
15
|
+
Resque::StuckQueue.redis.del("test-incr-key")
|
15
16
|
|
16
|
-
p1 = fork { Resque.redis.client.reconnect; run_resque_stuck_daemon; }
|
17
|
-
p2 = fork { Resque.redis.client.reconnect; run_resque_stuck_daemon; }
|
18
|
-
p3 = fork { Resque.redis.client.reconnect; run_resque_stuck_daemon; }
|
19
|
-
p4 = fork { Resque.redis.client.reconnect; run_resque_stuck_daemon; }
|
17
|
+
p1 = fork { Resque::StuckQueue.redis.client.reconnect; run_resque_stuck_daemon; }
|
18
|
+
p2 = fork { Resque::StuckQueue.redis.client.reconnect; run_resque_stuck_daemon; }
|
19
|
+
p3 = fork { Resque::StuckQueue.redis.client.reconnect; run_resque_stuck_daemon; }
|
20
|
+
p4 = fork { Resque::StuckQueue.redis.client.reconnect; run_resque_stuck_daemon; }
|
20
21
|
|
21
22
|
Thread.new {
|
22
23
|
sleep 5 # let test run and trigger once occur (according to time below)
|
@@ -29,7 +30,7 @@ class TestCollision < Minitest::Test
|
|
29
30
|
|
30
31
|
Process.waitall
|
31
32
|
|
32
|
-
assert_equal 1, Resque.redis.get("test-incr-key").to_i
|
33
|
+
assert_equal 1, Resque::StuckQueue.redis.get("test-incr-key").to_i
|
33
34
|
end
|
34
35
|
|
35
36
|
private
|
@@ -38,7 +39,7 @@ class TestCollision < Minitest::Test
|
|
38
39
|
Resque::StuckQueue.config[:heartbeat] = 1
|
39
40
|
Resque::StuckQueue.config[:abort_on_exception] = true
|
40
41
|
Resque::StuckQueue.config[:trigger_timeout] = 3
|
41
|
-
Resque::StuckQueue.config[:handler] = proc { Resque.redis.incr("test-incr-key") }
|
42
|
+
Resque::StuckQueue.config[:handler] = proc { Resque::StuckQueue.redis.incr("test-incr-key") }
|
42
43
|
Resque::StuckQueue.start
|
43
44
|
end
|
44
45
|
|
data/test/test_integration.rb
CHANGED
@@ -25,11 +25,14 @@ class TestIntegration < Minitest::Test
|
|
25
25
|
# ps aux |grep resqu |awk '{print $2}' | xargs kill
|
26
26
|
|
27
27
|
def setup
|
28
|
+
Resque::StuckQueue.redis = Redis.new
|
29
|
+
Resque::StuckQueue.redis.flushall
|
30
|
+
Resque::StuckQueue.config[:abort_on_exception] = true
|
28
31
|
end
|
29
32
|
|
30
33
|
def teardown
|
31
34
|
`kill -9 #{@resque_pid}` # CONT falls throughs sometimes? hax, rm this and SIGSTOP/SIGCONT
|
32
|
-
Resque::StuckQueue.
|
35
|
+
Resque::StuckQueue.force_stop!
|
33
36
|
Process.waitpid(@resque_pid)
|
34
37
|
end
|
35
38
|
|
@@ -43,10 +46,10 @@ class TestIntegration < Minitest::Test
|
|
43
46
|
|
44
47
|
# job gets enqueued successfully
|
45
48
|
@resque_pid = run_resque
|
46
|
-
Resque.redis.del(SetRedisKey::NAME)
|
47
|
-
Resque.
|
49
|
+
Resque::StuckQueue.redis.del(SetRedisKey::NAME)
|
50
|
+
Resque.enqueue_to(:app, SetRedisKey)
|
48
51
|
sleep 6 # let resque pick up the job
|
49
|
-
assert_equal Resque.redis.get(SetRedisKey::NAME), "1"
|
52
|
+
assert_equal Resque::StuckQueue.redis.get(SetRedisKey::NAME), "1" # job ran
|
50
53
|
|
51
54
|
# check handler did not get called
|
52
55
|
assert_equal @triggered, false
|
@@ -62,10 +65,10 @@ class TestIntegration < Minitest::Test
|
|
62
65
|
|
63
66
|
# job gets enqueued successfully
|
64
67
|
@resque_pid = run_resque
|
65
|
-
Resque.redis.del(SetRedisKey::NAME)
|
68
|
+
Resque::StuckQueue.redis.del(SetRedisKey::NAME)
|
66
69
|
Process.kill("SIGSTOP", @resque_pid) # jic, do not process jobs so we definitely trigger
|
67
70
|
Resque.enqueue(SetRedisKey)
|
68
|
-
assert_equal Resque.redis.get(SetRedisKey::NAME), nil
|
71
|
+
assert_equal Resque::StuckQueue.redis.get(SetRedisKey::NAME), nil
|
69
72
|
sleep 2 # allow timeout to trigger
|
70
73
|
|
71
74
|
# check handler did get called
|
data/test/test_named_queues.rb
CHANGED
@@ -8,12 +8,13 @@ class TestNamedQueues < Minitest::Test
|
|
8
8
|
Resque::StuckQueue.config[:trigger_timeout] = 1
|
9
9
|
Resque::StuckQueue.config[:heartbeat] = 1
|
10
10
|
Resque::StuckQueue.config[:abort_on_exception] = true
|
11
|
-
Resque.redis.
|
11
|
+
Resque::StuckQueue.redis = Redis.new
|
12
|
+
Resque::StuckQueue.redis.flushall
|
12
13
|
end
|
13
14
|
|
14
15
|
def teardown
|
15
16
|
`kill -9 #{@resque_pid}` if @resque_pid
|
16
|
-
Resque::StuckQueue.
|
17
|
+
Resque::StuckQueue.force_stop!
|
17
18
|
Process.waitpid(@resque_pid) if @resque_pid
|
18
19
|
end
|
19
20
|
|
@@ -35,8 +36,9 @@ class TestNamedQueues < Minitest::Test
|
|
35
36
|
puts "#{__method__}"
|
36
37
|
Resque::StuckQueue.config[:trigger_timeout] = 2 # won't allow waiting too much and will complain (eg trigger) sooner than later
|
37
38
|
Resque::StuckQueue.config[:heartbeat] = 1
|
39
|
+
Resque::StuckQueue.config[:queues] = [:custom_queue_name]
|
38
40
|
@triggered = false
|
39
|
-
Resque::StuckQueue.config[:handler] = proc { @triggered =
|
41
|
+
Resque::StuckQueue.config[:handler] = proc { |queue_name| @triggered = queue_name }
|
40
42
|
Resque::StuckQueue.start_in_background
|
41
43
|
|
42
44
|
# job gets enqueued successfully
|
@@ -44,7 +46,7 @@ class TestNamedQueues < Minitest::Test
|
|
44
46
|
sleep 2 # allow timeout to trigger
|
45
47
|
|
46
48
|
# check handler did get called
|
47
|
-
assert_equal @triggered,
|
49
|
+
assert_equal @triggered, :custom_queue_name
|
48
50
|
end
|
49
51
|
|
50
52
|
def test_resque_enqueues_a_job_correct_queue_does_not_trigger
|
data/test/test_resque_2.rb
CHANGED
@@ -16,12 +16,13 @@ if !ENV['RESQUE_2'].nil?
|
|
16
16
|
|
17
17
|
def setup
|
18
18
|
assert (Resque::VERSION.match /^2\./), "must run in 2.0"
|
19
|
+
Resque::StuckQueue.redis = Redis.new
|
19
20
|
Redis.new.flushall
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_works_with_2_point_oh_do_not_trigger_because_key_is_updated
|
23
24
|
|
24
|
-
Resque.redis = Redis.new
|
25
|
+
Resque::StuckQueue.redis = Redis.new
|
25
26
|
|
26
27
|
Resque::StuckQueue.config[:heartbeat] = 1
|
27
28
|
Resque::StuckQueue.config[:abort_on_exception] = true
|
@@ -33,7 +34,7 @@ if !ENV['RESQUE_2'].nil?
|
|
33
34
|
#binding.pry
|
34
35
|
Resque::StuckQueue.start_in_background
|
35
36
|
|
36
|
-
@r2_pid = fork { Resque.redis = Redis.new ; Resque::Worker.new("*", :graceful_term => true).work ; Process.waitall }
|
37
|
+
@r2_pid = fork { Resque::StuckQueue.redis = Redis.new ; Resque::Worker.new("*", :graceful_term => true).work ; Process.waitall }
|
37
38
|
sleep 10
|
38
39
|
|
39
40
|
# did not trigger, resque picked up refresh jobs
|
@@ -13,17 +13,18 @@ class TestResqueStuckQueue < Minitest::Test
|
|
13
13
|
def setup
|
14
14
|
puts "#{__method__}"
|
15
15
|
# clean previous test runs
|
16
|
-
Resque.redis.
|
16
|
+
Resque::StuckQueue.redis = Redis.new
|
17
|
+
Resque::StuckQueue.redis.flushall
|
17
18
|
Resque::StuckQueue.config[:heartbeat] = 1 # seconds
|
18
19
|
Resque::StuckQueue.config[:abort_on_exception] = true
|
19
20
|
end
|
20
21
|
|
21
22
|
def test_configure_global_key
|
22
23
|
puts "#{__method__}"
|
23
|
-
assert_nil Resque.redis.get("it-is-configurable"), "global key should not be set"
|
24
|
+
assert_nil Resque::StuckQueue.redis.get("it-is-configurable"), "global key should not be set"
|
24
25
|
Resque::StuckQueue.config[:global_key] = "it-is-configurable"
|
25
26
|
start_and_stop_loops_after(2)
|
26
|
-
refute_nil Resque.redis.get("app:it-is-configurable"), "global key should be set"
|
27
|
+
refute_nil Resque::StuckQueue.redis.get("app:it-is-configurable"), "global key should be set"
|
27
28
|
end
|
28
29
|
|
29
30
|
def test_it_does_not_trigger_handler_if_under_max_time
|
@@ -9,7 +9,8 @@ class TestYourOwnRefreshJob < Minitest::Test
|
|
9
9
|
Resque::StuckQueue.config[:heartbeat] = 1
|
10
10
|
Resque::StuckQueue.config[:abort_on_exception] = true
|
11
11
|
Resque::StuckQueue.config[:refresh_job] = nil
|
12
|
-
Resque.redis.
|
12
|
+
Resque::StuckQueue.redis = Redis.new
|
13
|
+
Resque::StuckQueue.redis.flushall
|
13
14
|
end
|
14
15
|
|
15
16
|
def teardown
|