resque_stuck_queue 0.0.3 → 0.0.4
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 +8 -8
- data/lib/resque_stuck_queue/version.rb +1 -1
- data/lib/resque_stuck_queue.rb +15 -5
- data/test/test_resque_stuck_queue.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWE1YzA3NjU4NjE1NGQ3ZjQ4OGMwNzRlZDE3Nzk4ZDhlOTc2YjM4YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTBiNGVhN2U5ZjYzMzkwOWJkNDc4Y2ViZTcyOTFjOWNlMjJmZDdiNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmMxMzgzYTRhM2QyNDg4YTAyYjcxMTE4Y2RmYmNhMWJjNTBlZGVmOGMxNWRk
|
10
|
+
MTYxZTEyN2MyODc1NTNiODljYWRlZWUxZDgzZGExZjM5NzFkZjAzYTU5Y2M2
|
11
|
+
YmQyMDc0ZGFjOTlhYWFlNTM4YzFmY2M3NTI2ZTliYjcyZTA2NzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWY2ODg5NGEwN2Q2ZGI3ODcyMWRmZjk5OGU3NTA0ZDgyMDkxNmQ1NzIzZTM3
|
14
|
+
M2ExODE3NDA4NjNiMTE0ZDE5ZDdiNWEyMDE3ZjFhNDYyZTgzYTEzNTM0M2I3
|
15
|
+
YWEzMjc0MjFmMDFlZGNkOTk3M2YwNWY3ZjBlZjY4MWQzMzQzOTI=
|
data/lib/resque_stuck_queue.rb
CHANGED
@@ -46,12 +46,14 @@ module Resque
|
|
46
46
|
|
47
47
|
def start_in_background
|
48
48
|
Thread.new do
|
49
|
+
Thread.current.abort_on_exception = config[:abort_on_exception]
|
49
50
|
self.start
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
54
|
def stop_in_background
|
54
55
|
Thread.new do
|
56
|
+
Thread.current.abort_on_exception = config[:abort_on_exception]
|
55
57
|
self.start
|
56
58
|
end
|
57
59
|
end
|
@@ -63,7 +65,6 @@ module Resque
|
|
63
65
|
@threads = []
|
64
66
|
config.freeze
|
65
67
|
|
66
|
-
Thread.abort_on_exception = config[:abort_on_exception]
|
67
68
|
|
68
69
|
enqueue_repeating_refresh_job
|
69
70
|
setup_checker_thread
|
@@ -85,40 +86,45 @@ module Resque
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def force_stop!
|
89
|
+
logger.info("Force stopping")
|
88
90
|
@threads.map(&:kill)
|
89
91
|
reset!
|
90
|
-
logger.info("Force stopped")
|
91
92
|
end
|
92
93
|
|
93
94
|
def reset!
|
94
95
|
# clean state so we can stop and start in the same process.
|
95
96
|
@config = config.dup #unfreeze
|
96
|
-
@logger = nil
|
97
97
|
@running = false
|
98
|
+
@logger = nil
|
99
|
+
end
|
100
|
+
|
101
|
+
def stopped?
|
102
|
+
@stopped
|
98
103
|
end
|
99
104
|
|
100
105
|
private
|
101
106
|
|
102
107
|
def enqueue_repeating_refresh_job
|
103
108
|
@threads << Thread.new do
|
109
|
+
Thread.current.abort_on_exception = config[:abort_on_exception]
|
104
110
|
logger.info("Starting heartbeat thread")
|
105
111
|
while @running
|
106
|
-
wait_for_it
|
107
112
|
# we want to go through resque jobs, because that's what we're trying to test here:
|
108
113
|
# ensure that jobs get executed and the time is updated!
|
109
114
|
#
|
110
115
|
# TODO REDIS 2.0 compat
|
111
116
|
logger.info("Sending refresh job")
|
112
117
|
Resque.enqueue(RefreshLatestTimestamp, global_key)
|
118
|
+
wait_for_it
|
113
119
|
end
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
117
123
|
def setup_checker_thread
|
118
124
|
@threads << Thread.new do
|
125
|
+
Thread.current.abort_on_exception = config[:abort_on_exception]
|
119
126
|
logger.info("Starting checker thread")
|
120
127
|
while @running
|
121
|
-
wait_for_it
|
122
128
|
mutex = Redis::Mutex.new('resque_stuck_queue_lock', block: 0)
|
123
129
|
if mutex.lock
|
124
130
|
begin
|
@@ -130,6 +136,7 @@ module Resque
|
|
130
136
|
mutex.unlock
|
131
137
|
end
|
132
138
|
end
|
139
|
+
wait_for_it
|
133
140
|
end
|
134
141
|
end
|
135
142
|
end
|
@@ -152,6 +159,9 @@ module Resque
|
|
152
159
|
def trigger_handler
|
153
160
|
(config[:handler] || HANDLER).call
|
154
161
|
manual_refresh
|
162
|
+
rescue => e
|
163
|
+
logger.info("handler crashed: #{e.inspect}")
|
164
|
+
force_stop!
|
155
165
|
end
|
156
166
|
|
157
167
|
def read_from_redis
|
@@ -49,5 +49,20 @@ class TestResqueStuckQueue < Minitest::Test
|
|
49
49
|
assert_equal true, @triggered # "handler should be called"
|
50
50
|
end
|
51
51
|
|
52
|
+
def test_stops_if_handler_raises
|
53
|
+
puts "#{__method__}"
|
54
|
+
Resque::StuckQueue.config[:trigger_timeout] = 1
|
55
|
+
last_time_too_old = Time.now.to_i - Resque::StuckQueue::TRIGGER_TIMEOUT
|
56
|
+
Resque::StuckQueue.stubs(:read_from_redis).returns(last_time_too_old.to_s) # enforce trigger
|
57
|
+
Resque::StuckQueue.config[:handler] = proc { raise "handler had bad sad!" }
|
58
|
+
Thread.new {
|
59
|
+
sleep 3 # should have triggered
|
60
|
+
Thread.current.abort_on_exception = true
|
61
|
+
assert Resque::StuckQueue.stopped?, "should stop stuck_queue if handler raises."
|
62
|
+
}
|
63
|
+
start_and_stop_loops_after(4)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
52
67
|
end
|
53
68
|
|