resque_stuck_queue 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +7 -2
- data/Gemfile.lock +13 -21
- data/README.md +2 -0
- data/lib/resque_stuck_queue.rb +17 -8
- data/lib/resque_stuck_queue/version.rb +1 -1
- data/test/resque/refresh_latest_timestamp.rb +4 -2
- data/test/test_helper.rb +0 -1
- data/test/test_resque_2.rb +49 -0
- data/test/test_resque_stuck_queue.rb +0 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA512:
|
3
|
-
metadata.gz: 9a0277c13278dc4044d3da46038e8abf0a1cb44d43ec4acc858e8b2c17519f215468f627a2025e7a680a3d97dc28938314babaf2ac4dc62170afaef0248e63b6
|
4
|
-
data.tar.gz: b7864ee5d7d1e3e185f87f6dd016725016e8595b82c78d9d69a90a7eaf02b3b7a366002859a0c7b1f2d030ebdd5b0d4a4b7adbe7757efe950ff970f1ee48d750
|
5
2
|
SHA1:
|
6
|
-
|
7
|
-
|
3
|
+
data.tar.gz: 45a7b50263556a7d07eaaee7c006033479ba01f2
|
4
|
+
metadata.gz: 8b0c17d7a88388d815317a82502f37f6f57d3a8a
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: eb8d73f5882b34d63c5cee3cf4cb8bec0e66a2c9b3f30355772042284a93c98bf01357e936fab39904015c5f093588d471af1583daaf8cff6c856870b35fef48
|
7
|
+
metadata.gz: 714f459c5ae47a20353efc148050a2e7957557776110852266688e84d9c3ab36a908831b56a5fde7d18293181569722f925716c1ac7fbd3e0c9b0762bd59648b
|
data/Gemfile
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
if ENV['RESQUE_2']
|
4
|
+
# resque 2
|
5
|
+
gem 'resque', :git => "https://github.com/engineyard/resque.git"
|
6
|
+
else
|
7
|
+
gem 'resque'
|
8
|
+
end
|
9
|
+
|
4
10
|
gem 'redis-mutex'
|
5
11
|
|
6
12
|
# TEST
|
7
13
|
gem 'minitest'
|
8
14
|
gem 'mocha'
|
9
|
-
gem 'resque-mock'
|
10
15
|
gem 'pry'
|
11
16
|
gem 'rake'
|
12
17
|
gem 'm'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/engineyard/resque.git
|
3
|
+
revision: 2949f9f5b035c59a7c03999c00558544837324b5
|
4
|
+
specs:
|
5
|
+
resque (2.0.0.pre.1)
|
6
|
+
json
|
7
|
+
mono_logger (~> 1.0)
|
8
|
+
redis-namespace (>= 1.3.0)
|
9
|
+
thor (~> 0.17)
|
10
|
+
|
1
11
|
GEM
|
2
12
|
remote: https://rubygems.org/
|
3
13
|
specs:
|
4
14
|
coderay (1.1.0)
|
15
|
+
json (1.8.1)
|
5
16
|
m (1.3.2)
|
6
17
|
method_source (>= 0.6.7)
|
7
18
|
rake (>= 0.9.2.2)
|
@@ -11,14 +22,10 @@ GEM
|
|
11
22
|
mocha (0.14.0)
|
12
23
|
metaclass (~> 0.0.1)
|
13
24
|
mono_logger (1.1.0)
|
14
|
-
multi_json (1.8.2)
|
15
25
|
pry (0.9.12.4)
|
16
26
|
coderay (~> 1.0)
|
17
27
|
method_source (~> 0.8)
|
18
28
|
slop (~> 3.4)
|
19
|
-
rack (1.5.2)
|
20
|
-
rack-protection (1.5.1)
|
21
|
-
rack
|
22
29
|
rake (10.1.0)
|
23
30
|
redis (3.0.6)
|
24
31
|
redis-classy (1.2.0)
|
@@ -27,29 +34,15 @@ GEM
|
|
27
34
|
redis-classy (~> 1.2)
|
28
35
|
redis-namespace (1.4.1)
|
29
36
|
redis (~> 3.0.4)
|
30
|
-
resque (1.25.1)
|
31
|
-
mono_logger (~> 1.0)
|
32
|
-
multi_json (~> 1.0)
|
33
|
-
redis-namespace (~> 1.2)
|
34
|
-
sinatra (>= 0.9.2)
|
35
|
-
vegas (~> 0.1.2)
|
36
|
-
resque-mock (0.1.1)
|
37
|
-
resque
|
38
37
|
resque-scheduler (2.0.1)
|
39
38
|
redis (>= 2.0.1)
|
40
39
|
resque (>= 1.20.0)
|
41
40
|
rufus-scheduler
|
42
41
|
rufus-scheduler (2.0.19)
|
43
42
|
tzinfo (>= 0.3.23)
|
44
|
-
sinatra (1.4.4)
|
45
|
-
rack (~> 1.4)
|
46
|
-
rack-protection (~> 1.4)
|
47
|
-
tilt (~> 1.3, >= 1.3.4)
|
48
43
|
slop (3.4.7)
|
49
|
-
|
44
|
+
thor (0.18.1)
|
50
45
|
tzinfo (0.3.38)
|
51
|
-
vegas (0.1.11)
|
52
|
-
rack (>= 1.0.0)
|
53
46
|
|
54
47
|
PLATFORMS
|
55
48
|
ruby
|
@@ -61,6 +54,5 @@ DEPENDENCIES
|
|
61
54
|
pry
|
62
55
|
rake
|
63
56
|
redis-mutex
|
64
|
-
resque
|
65
|
-
resque-mock
|
57
|
+
resque!
|
66
58
|
resque-scheduler
|
data/README.md
CHANGED
@@ -47,6 +47,8 @@ Resque::StuckQueue.config[:abort_on_exception] = true
|
|
47
47
|
# optional, pass a logger. Default a ruby logger will be instantiated. Needs to respond to that interface.
|
48
48
|
Resque::StuckQueue.config[:logger] = Logger.new($stdout)
|
49
49
|
|
50
|
+
# optional, pass a redis.
|
51
|
+
Resque::StuckQueue.config[:redis] = Redis.new
|
50
52
|
</pre>
|
51
53
|
|
52
54
|
Then start it:
|
data/lib/resque_stuck_queue.rb
CHANGED
@@ -5,7 +5,6 @@ require 'resque'
|
|
5
5
|
|
6
6
|
# TODO rm redis-mutex dep and just do the setnx locking here
|
7
7
|
require 'redis-mutex'
|
8
|
-
Redis::Classy.db = Resque.redis
|
9
8
|
|
10
9
|
require 'logger'
|
11
10
|
|
@@ -36,6 +35,9 @@ module Resque
|
|
36
35
|
#
|
37
36
|
# # default handler
|
38
37
|
# config[:handler] = proc { send_mail }
|
38
|
+
#
|
39
|
+
# # explicit redis
|
40
|
+
# config[:redis] = Redis.new
|
39
41
|
def config
|
40
42
|
@config ||= {}
|
41
43
|
end
|
@@ -44,6 +46,10 @@ module Resque
|
|
44
46
|
@logger ||= (config[:logger] || Logger.new($stdout))
|
45
47
|
end
|
46
48
|
|
49
|
+
def redis
|
50
|
+
@redis ||= (config[:redis] || Resque.redis)
|
51
|
+
end
|
52
|
+
|
47
53
|
def start_in_background
|
48
54
|
Thread.new do
|
49
55
|
Thread.current.abort_on_exception = config[:abort_on_exception]
|
@@ -58,6 +64,7 @@ module Resque
|
|
58
64
|
@threads = []
|
59
65
|
config.freeze
|
60
66
|
|
67
|
+
Redis::Classy.db = redis if Redis::Classy.db.nil?
|
61
68
|
|
62
69
|
enqueue_repeating_refresh_job
|
63
70
|
setup_checker_thread
|
@@ -109,8 +116,6 @@ module Resque
|
|
109
116
|
while @running
|
110
117
|
# we want to go through resque jobs, because that's what we're trying to test here:
|
111
118
|
# ensure that jobs get executed and the time is updated!
|
112
|
-
#
|
113
|
-
# TODO REDIS 2.0 compat
|
114
119
|
logger.info("Sending refresh job")
|
115
120
|
enqueue_job
|
116
121
|
wait_for_it
|
@@ -122,7 +127,7 @@ module Resque
|
|
122
127
|
if config[:refresh_job]
|
123
128
|
config[:refresh_job].call
|
124
129
|
else
|
125
|
-
Resque.enqueue(RefreshLatestTimestamp, global_key)
|
130
|
+
Resque.enqueue(RefreshLatestTimestamp, [global_key, redis.client.host, redis.client.port])
|
126
131
|
end
|
127
132
|
end
|
128
133
|
|
@@ -158,7 +163,7 @@ module Resque
|
|
158
163
|
|
159
164
|
def manual_refresh
|
160
165
|
time = Time.now.to_i
|
161
|
-
|
166
|
+
redis.set(global_key, time)
|
162
167
|
time
|
163
168
|
end
|
164
169
|
|
@@ -171,7 +176,7 @@ module Resque
|
|
171
176
|
end
|
172
177
|
|
173
178
|
def read_from_redis
|
174
|
-
|
179
|
+
redis.get(global_key)
|
175
180
|
end
|
176
181
|
|
177
182
|
def wait_for_it
|
@@ -187,7 +192,11 @@ end
|
|
187
192
|
|
188
193
|
class RefreshLatestTimestamp
|
189
194
|
@queue = :app
|
190
|
-
def self.perform(
|
191
|
-
|
195
|
+
def self.perform(args)
|
196
|
+
timestamp_key = args[0]
|
197
|
+
host = args[1] || "localhost"
|
198
|
+
port = args[2] || "6379"
|
199
|
+
r = Redis.new(:host => host, :port => port)
|
200
|
+
r.set(timestamp_key, Time.now.to_i)
|
192
201
|
end
|
193
202
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class RefreshLatestTimestamp
|
2
2
|
@queue = :app
|
3
|
-
def self.perform(
|
4
|
-
|
3
|
+
def self.perform(args)
|
4
|
+
timestamp_key, host, port = args[0], args[1], args[2]
|
5
|
+
r = Redis.new(:host => host, :port => port)
|
6
|
+
r.set(timestamp_key, Time.now.to_i)
|
5
7
|
end
|
6
8
|
end
|
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
# run with
|
2
|
+
# $ RESQUE_2=1 bi; RESQUE_2=1 be ruby -I. -Ilib/ test/test_resque_2.rb
|
3
|
+
if !ENV['RESQUE_2'].nil?
|
4
|
+
|
5
|
+
require 'minitest'
|
6
|
+
require "minitest/autorun"
|
7
|
+
require "pry"
|
8
|
+
require "logger"
|
9
|
+
|
10
|
+
$:.unshift(".")
|
11
|
+
require "resque_stuck_queue"
|
12
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "resque", "set_redis_key")
|
13
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "resque", "refresh_latest_timestamp")
|
14
|
+
|
15
|
+
class TestResque2 < Minitest::Test
|
16
|
+
|
17
|
+
def setup
|
18
|
+
assert (Resque::VERSION.match /^2\./), "must run in 2.0"
|
19
|
+
Redis.new.flushall
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_works_with_2_point_oh_do_not_trigger_because_key_is_updated
|
23
|
+
|
24
|
+
Resque.redis = Redis.new
|
25
|
+
|
26
|
+
Resque::StuckQueue.config[:heartbeat] = 1
|
27
|
+
Resque::StuckQueue.config[:abort_on_exception] = true
|
28
|
+
Resque::StuckQueue.config[:trigger_timeout] = 5
|
29
|
+
Resque::StuckQueue.config[:logger] = Logger.new($stdout)
|
30
|
+
Resque::StuckQueue.config[:handler] = proc { Redis.new.incr("test-incr-key") }
|
31
|
+
Resque::StuckQueue.config[:redis] = Redis.new
|
32
|
+
|
33
|
+
#binding.pry
|
34
|
+
Resque::StuckQueue.start_in_background
|
35
|
+
|
36
|
+
@r2_pid = fork { Resque.redis = Redis.new ; Resque::Worker.new("*", :graceful_term => true).work ; Process.waitall }
|
37
|
+
sleep 10
|
38
|
+
|
39
|
+
# did not trigger, resque picked up refresh jobs
|
40
|
+
assert_equal Redis.new.get("test-incr-key").to_i, 0
|
41
|
+
|
42
|
+
`kill #{@r2_pid}`
|
43
|
+
Process.waitall
|
44
|
+
Resque::StuckQueue.force_stop!
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_stuck_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shai Rosenfeld
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- test/test_helper.rb
|
68
68
|
- test/test_integration.rb
|
69
69
|
- test/test_logger.rb
|
70
|
+
- test/test_resque_2.rb
|
70
71
|
- test/test_resque_stuck_queue.rb
|
71
72
|
- test/test_set_custom_refresh_job.rb
|
72
73
|
homepage: https://github.com/shaiguitar/resque_stuck_queue/
|
@@ -99,5 +100,6 @@ test_files:
|
|
99
100
|
- test/test_helper.rb
|
100
101
|
- test/test_integration.rb
|
101
102
|
- test/test_logger.rb
|
103
|
+
- test/test_resque_2.rb
|
102
104
|
- test/test_resque_stuck_queue.rb
|
103
105
|
- test/test_set_custom_refresh_job.rb
|