resque_stuck_queue 0.0.5 → 0.0.6
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 +7 -15
- data/README.md +21 -1
- data/THOUGHTS +1 -0
- data/lib/resque_stuck_queue.rb +14 -5
- data/lib/resque_stuck_queue/version.rb +1 -1
- data/test/test_set_your_own_refresh_job.rb +56 -0
- metadata +49 -58
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
Mzg5ZTUyOWVhMjQzYTkwNmQ3YmQ2NDc0MDAzZGU4NWZhNTkxYWE3ODM0N2Jk
|
10
|
-
NzBlYTdlOTliMTNkOGIyYzc2ZDU2MmU4ZmJlYzllNGVhZjExNzk4MWY0Mzlj
|
11
|
-
MGRjM2FlNmNlY2RkZWE4NGRiNTJmN2IxOTY5M2EyZDhkZjFlMWQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Yjc3ZWJmN2Y3OGM3NDk0ODMzMGJjNzcxMWIzMGRkY2Q2NWQxNTdiNGU3OTQ1
|
14
|
-
NDU3NmRmNDMxMmRhYzk1ZmU1OTViYTJhZmY5ZjkwNGMxYTEwZjY5N2QzZmI1
|
15
|
-
ZThmYWMyYWE5OTgzNGRjNGJiMGZiMDczOWQ4ZmRiNmZkMDdmNWM=
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
data.tar.gz: f3bb5b9529929905d39cbe224c3be24be7a140a3
|
4
|
+
metadata.gz: 22cdb53ee5c30b9ba2fac0e44a029e9163980cc6
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: c9ab5e52097a9f8d98620d9e9c4c337d60bee4594a3a9b827607139a5fd913e78b0e56b13355977d9430b81c09265c3d9c544f5d53e82652911c8bd44e4cd8ed
|
7
|
+
metadata.gz: 84d36d31275f1be8ba45fadf880226bdbe582612e18ce54009e422e2b274b4a873077f735141e7bcd5f55bf9e263ec7b9c7cd05cc538f913df23698c69bcd65e
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ Contrived example:
|
|
77
77
|
|
78
78
|
# put this in lib/tasks/resque_stuck_queue.rb
|
79
79
|
|
80
|
-
require 'resque_stuck_queue'
|
80
|
+
require 'resque_stuck_queue' # or require 'resque/stuck_queue'
|
81
81
|
|
82
82
|
namespace :resque do
|
83
83
|
desc "Start a Resque-stuck daemon"
|
@@ -99,6 +99,26 @@ $ bundle exec rake --trace resque:stuck_queue
|
|
99
99
|
|
100
100
|
</pre>
|
101
101
|
|
102
|
+
## Sidekiq/Other redis-based job queues
|
103
|
+
|
104
|
+
If you have trouble with other queues you can use this lib by setting your own custom refresh job (aka, the job that refreshes the global_key). The one thing you need to take care of is ensure whatever and however you enque your own custom job, it sets the global_key to Time.now. Then do:
|
105
|
+
|
106
|
+
<pre>
|
107
|
+
|
108
|
+
class CustomJob
|
109
|
+
include Sidekiq::Worker
|
110
|
+
def perform
|
111
|
+
# ensure you're setting the key in the redis the job queue is using
|
112
|
+
$redis.set(Resque::StuckQueue.global_key, Time.now.to_i)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
Resque::StuckQueue.config[:refresh_job] = proc {
|
117
|
+
# or however else you enque your custom job, Sidekiq::Client.enqueue(CustomJob), whatever, etc.
|
118
|
+
CustomJob.perform_async
|
119
|
+
}
|
120
|
+
</pre>
|
121
|
+
|
102
122
|
## Tests
|
103
123
|
|
104
124
|
Run the tests:
|
data/THOUGHTS
CHANGED
@@ -10,3 +10,4 @@ add daemon example to readme
|
|
10
10
|
add a 'resque_stuck_queue/tasks' bit? See tres eg
|
11
11
|
require 'resque/stuck_queue' instead?
|
12
12
|
ensure the logging gets flushed into log file correctly? (integration with god?)
|
13
|
+
add a trap{} to force_stop. ok for overwriting process's trap handlers? use config for that?
|
data/lib/resque_stuck_queue.rb
CHANGED
@@ -95,6 +95,11 @@ module Resque
|
|
95
95
|
@stopped
|
96
96
|
end
|
97
97
|
|
98
|
+
def global_key
|
99
|
+
# public, for use in custom heartbeat job
|
100
|
+
config[:global_key] || GLOBAL_KEY
|
101
|
+
end
|
102
|
+
|
98
103
|
private
|
99
104
|
|
100
105
|
def enqueue_repeating_refresh_job
|
@@ -107,12 +112,20 @@ module Resque
|
|
107
112
|
#
|
108
113
|
# TODO REDIS 2.0 compat
|
109
114
|
logger.info("Sending refresh job")
|
110
|
-
|
115
|
+
enqueue_job
|
111
116
|
wait_for_it
|
112
117
|
end
|
113
118
|
end
|
114
119
|
end
|
115
120
|
|
121
|
+
def enqueue_job
|
122
|
+
if config[:refresh_job]
|
123
|
+
config[:refresh_job].call
|
124
|
+
else
|
125
|
+
Resque.enqueue(RefreshLatestTimestamp, global_key)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
116
129
|
def setup_checker_thread
|
117
130
|
@threads << Thread.new do
|
118
131
|
Thread.current.abort_on_exception = config[:abort_on_exception]
|
@@ -165,10 +178,6 @@ module Resque
|
|
165
178
|
sleep config[:heartbeat] || HEARTBEAT
|
166
179
|
end
|
167
180
|
|
168
|
-
def global_key
|
169
|
-
config[:global_key] || GLOBAL_KEY
|
170
|
-
end
|
171
|
-
|
172
181
|
def max_wait_time
|
173
182
|
config[:trigger_timeout] || TRIGGER_TIMEOUT
|
174
183
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
2
|
+
|
3
|
+
class TestYourOwnRefreshJob < Minitest::Test
|
4
|
+
|
5
|
+
include TestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Resque::StuckQueue.config[:trigger_timeout] = 1
|
9
|
+
Resque::StuckQueue.config[:heartbeat] = 1
|
10
|
+
Resque::StuckQueue.config[:abort_on_exception] = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
Resque::StuckQueue.reset!
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_will_trigger_with_unrefreshing_custom_heartbeat_job
|
18
|
+
# it will trigger because the key will be unrefreshed, hence 'old' and will always trigger.
|
19
|
+
puts "#{__method__}"
|
20
|
+
Resque::StuckQueue.config[:refresh_job] = proc { nil } # does not refresh global key
|
21
|
+
@triggered = false
|
22
|
+
Resque::StuckQueue.config[:handler] = proc { @triggered = true }
|
23
|
+
start_and_stop_loops_after(3)
|
24
|
+
assert @triggered, "will trigger because global key will be old"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_will_fail_with_bad_custom_heartbeat_job
|
28
|
+
puts "#{__method__}"
|
29
|
+
begin
|
30
|
+
Resque::StuckQueue.config[:refresh_job] = proc { raise 'bad proc doc' } # does not refresh global key
|
31
|
+
@triggered = false
|
32
|
+
Resque::StuckQueue.config[:handler] = proc { @triggered = true }
|
33
|
+
start_and_stop_loops_after(3)
|
34
|
+
assert false, "should not succeed with bad refresh_job"
|
35
|
+
rescue
|
36
|
+
assert true, "will fail with bad refresh_job"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def test_has_settable_custom_hearbeat_job
|
42
|
+
puts "#{__method__}"
|
43
|
+
begin
|
44
|
+
Resque::StuckQueue.config[:refresh_job] = proc { Resque.enqueue(RefreshLatestTimestamp, Resque::StuckQueue.global_key) }
|
45
|
+
@triggered = false
|
46
|
+
Resque::StuckQueue.config[:handler] = proc { @triggered = true }
|
47
|
+
start_and_stop_loops_after(3)
|
48
|
+
assert true, "should not have raised"
|
49
|
+
assert @triggered, "should have triggered"
|
50
|
+
rescue => e
|
51
|
+
assert false, "should have succeeded with good refresh_job.\n #{e.inspect}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
metadata
CHANGED
@@ -1,64 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_stuck_queue
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Shai Rosenfeld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
date: 2014-01-13 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
14
15
|
name: redis-mutex
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ! '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
16
|
prerelease: false
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
-
|
25
|
-
-
|
26
|
-
|
27
|
-
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- &id003
|
20
|
+
- ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :runtime
|
24
|
+
version_requirements: *id001
|
25
|
+
- !ruby/object:Gem::Dependency
|
28
26
|
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.5'
|
34
|
-
type: :development
|
35
27
|
prerelease: false
|
36
|
-
|
37
|
-
requirements:
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
38
30
|
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ! '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: "1.5"
|
48
33
|
type: :development
|
34
|
+
version_requirements: *id002
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
49
37
|
prerelease: false
|
50
|
-
|
51
|
-
requirements:
|
52
|
-
-
|
53
|
-
|
54
|
-
|
38
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- *id003
|
41
|
+
type: :development
|
42
|
+
version_requirements: *id004
|
55
43
|
description: where the wild things are. err, when resque gets stuck
|
56
|
-
email:
|
44
|
+
email:
|
57
45
|
- srosenfeld@engineyard.com
|
58
46
|
executables: []
|
47
|
+
|
59
48
|
extensions: []
|
49
|
+
|
60
50
|
extra_rdoc_files: []
|
61
|
-
|
51
|
+
|
52
|
+
files:
|
62
53
|
- .gitignore
|
63
54
|
- Gemfile
|
64
55
|
- Gemfile.lock
|
@@ -77,31 +68,31 @@ files:
|
|
77
68
|
- test/test_integration.rb
|
78
69
|
- test/test_logger.rb
|
79
70
|
- test/test_resque_stuck_queue.rb
|
71
|
+
- test/test_set_your_own_refresh_job.rb
|
80
72
|
homepage: https://github.com/shaiguitar/resque_stuck_queue/
|
81
|
-
licenses:
|
73
|
+
licenses:
|
82
74
|
- MIT
|
83
75
|
metadata: {}
|
76
|
+
|
84
77
|
post_install_message:
|
85
78
|
rdoc_options: []
|
86
|
-
|
79
|
+
|
80
|
+
require_paths:
|
87
81
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
requirements:
|
95
|
-
- - ! '>='
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- *id003
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- *id003
|
98
88
|
requirements: []
|
89
|
+
|
99
90
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.0.
|
91
|
+
rubygems_version: 2.0.14
|
101
92
|
signing_key:
|
102
93
|
specification_version: 4
|
103
94
|
summary: fire a handler when your queues are wonky
|
104
|
-
test_files:
|
95
|
+
test_files:
|
105
96
|
- test/resque/refresh_latest_timestamp.rb
|
106
97
|
- test/resque/set_redis_key.rb
|
107
98
|
- test/test_collision.rb
|
@@ -109,4 +100,4 @@ test_files:
|
|
109
100
|
- test/test_integration.rb
|
110
101
|
- test/test_logger.rb
|
111
102
|
- test/test_resque_stuck_queue.rb
|
112
|
-
|
103
|
+
- test/test_set_your_own_refresh_job.rb
|