resque_stuck_queue 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 21e22e07449416caa592d83157978103b6d3cb25
4
- data.tar.gz: 52261706a53625364f3bddc7c531e8e1a1e38fa8
5
2
  SHA512:
6
- metadata.gz: 8da0b6facf25ed6034205a78d0ace7cac2c62aae772b6fbd0a2ae4c7d4fa5964f61f7ee341b7c784ef3e30b89561d4cff1fb012faf97f3206d1e54a87845b0d3
7
- data.tar.gz: e1fa87dff4f06d265d2e9a9a5facfe84fa9a1d42891c1f1e259f3850c8fe9ce10e032eeff2b9955bdf827ba5142520f542bc318ee8879669fbee2e1c524f9a9f
3
+ data.tar.gz: c61972d3ea6fbc28feaf6b720c24fa48c3d78ce06967e2b00762fb5dd3dd6d6ad1014616300b37299ee693b9c4a25dcddfc30a923b85285b35d24fe383639a6c
4
+ metadata.gz: f3e6cb7aeb0843612de8ccaccd6fcea4efab227d525ca3dcfca053d70e13a229ddd24ae8b43dc4cdc9b5c6bf3bd940fd1fa26dc8657f2ba248fc3fdbe85c590d
5
+ SHA1:
6
+ data.tar.gz: 1347fccc7e4b37ea0a0626a176d904c223c4d21b
7
+ metadata.gz: 9f217dadd17a7ff267b66b858330218c1e9f24fc
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gemspec
4
+
3
5
  if ENV['RESQUE_2']
4
6
  # resque 2
5
7
  gem 'resque', :git => "https://github.com/engineyard/resque.git"
data/README.md CHANGED
@@ -41,7 +41,7 @@ triggered_handler:
41
41
  Resque::StuckQueue.config[:triggered_handler] = proc { |queue_name, lagtime| send_email('queue #{queue_name} isnt working, aaah the daemons') }
42
42
 
43
43
  recovered_handler:
44
- set to what gets triggered when resque-stuck-queue has triggered a problem, but then detects the queue went back down to functioning well again (it wont trigger again until it has recovered).
44
+ set to what gets triggered when resque-stuck-queue has triggered a problem, but then detects the queue went back down to functioning well again(it wont trigger again until it has recovered).
45
45
  Example:
46
46
  Resque::StuckQueue.config[:recovered_handler] = proc { |queue_name, lagtime| send_email('phew, queue #{queue_name} is ok') }
47
47
 
@@ -56,7 +56,7 @@ trigger_timeout:
56
56
  Resque::StuckQueue.config[:trigger_timeout] = 55.minutes
57
57
 
58
58
  redis:
59
- set the Redis instance StuckQueue will use
59
+ set the Redis StuckQueue will use. Either a Redis or Redis::Namespace instance.
60
60
 
61
61
  heartbeat_key:
62
62
  optional, name of keys to keep track of the last good resque heartbeat time
@@ -75,7 +75,6 @@ abort_on_exception:
75
75
 
76
76
  heartbeat_job:
77
77
  optional, your own custom refreshing job. if you are using something other than resque
78
-
79
78
  </pre>
80
79
 
81
80
  To start it:
@@ -25,13 +25,8 @@ module Resque
25
25
  end
26
26
 
27
27
  def redis
28
- @redis ||= (config[:redis] || Resque.redis)
29
- end
30
-
31
- def redis=(rds)
32
- # for resq2 tests
33
- @redis = rds
34
- Resque.redis = @redis
28
+ @redis ||= (config[:redis] || raise(Config::NoConfigError, "Must configure a redis instance to use. Please set a Redis or Redis::Namespace."))
29
+ HeartbeatJob.redis = @redis
35
30
  end
36
31
 
37
32
  def heartbeat_key_for(queue)
@@ -142,7 +137,7 @@ module Resque
142
137
  config[:heartbeat_job].call
143
138
  else
144
139
  queues.each do |queue_name|
145
- Resque.enqueue_to(queue_name, HeartbeatJob, [heartbeat_key_for(queue_name), redis.client.host, redis.client.port])
140
+ Resque.enqueue_to(queue_name, HeartbeatJob, heartbeat_key_for(queue_name))
146
141
  end
147
142
  end
148
143
  end
@@ -19,13 +19,14 @@ module Resque
19
19
  :recovered_handler => "set to what gets triggered when resque-stuck-queue has triggered a problem, but then detects the queue went back down to functioning well again(it wont trigger again until it has recovered).\n\tExample:\n\tResque::StuckQueue.config[:recovered_handler] = proc { |queue_name, lagtime| send_email('phew, queue \#{queue_name} is ok') }",
20
20
  :heartbeat => "set to how often to push that 'heartbeat' job to refresh the latest time it worked.\n\tExample:\n\tResque::StuckQueue.config[:heartbeat] = 5.minutes",
21
21
  :trigger_timeout => "set to how much of a resque work lag you are willing to accept before being notified. note: take the :heartbeat setting into account when setting this timeout.\n\tExample:\n\tResque::StuckQueue.config[:trigger_timeout] = 55.minutes",
22
- :redis => "set the Redis instance StuckQueue will use",
22
+ :redis => "set the Redis StuckQueue will use. Either a Redis or Redis::Namespace instance.",
23
+
23
24
  :heartbeat_key => "optional, name of keys to keep track of the last good resque heartbeat time",
24
25
  :triggered_key => "optional, name of keys to keep track of the last trigger time",
25
26
  :logger => "optional, pass a Logger. Default a ruby logger will be instantiated. Needs to respond to that interface.",
26
27
  :queues => "optional, monitor specific queues you want to send a heartbeat/monitor to. default is :app",
27
28
  :abort_on_exception => "optional, if you want the resque-stuck-queue threads to explicitly raise, default is false",
28
- :heartbeat_job => "optional, your own custom refreshing job. if you are using something other than resque",
29
+ :heartbeat_job => "optional, your own custom refreshing job. if you are using something other than resque",
29
30
  }
30
31
 
31
32
  OPTIONS = OPTIONS_DESCRIPTIONS.keys
@@ -1,13 +1,14 @@
1
1
  module Resque
2
2
  module StuckQueue
3
3
  class HeartbeatJob
4
- def self.perform(args)
5
- timestamp_key = args[0]
6
- host = args[1]
7
- port = args[2]
8
- new_time = Time.now.to_i
9
- r = Redis.new(:host => host, :port => port)
10
- r.set(timestamp_key, new_time)
4
+ class << self
5
+
6
+ attr_accessor :redis
7
+
8
+ def perform(keyname)
9
+ @redis.set(keyname, Time.now.to_i)
10
+ end
11
+
11
12
  end
12
13
  end
13
14
  end
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  module StuckQueue
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "redis-mutex"
21
+ spec.add_runtime_dependency "redis-mutex" # TODO rm this
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "redis-namespace"
25
26
  end
@@ -5,7 +5,7 @@ class TestCollision < Minitest::Test
5
5
  include TestHelper
6
6
 
7
7
  def setup
8
- Resque::StuckQueue.redis = Redis.new
8
+ Resque::StuckQueue.config[:redis] = Redis.new
9
9
  Resque::StuckQueue.redis.flushall
10
10
  end
11
11
 
@@ -37,7 +37,7 @@ class TestIntegration < Minitest::Test
37
37
  end
38
38
 
39
39
  def setup
40
- Resque::StuckQueue.redis = Redis.new
40
+ Resque::StuckQueue.config[:redis] = Redis.new
41
41
  Resque::StuckQueue.redis.flushall
42
42
  Resque::StuckQueue.config[:abort_on_exception] = true
43
43
  self.class.run_resque_before_all
data/test/test_lagtime.rb CHANGED
@@ -12,7 +12,7 @@ class TestLagTime < Minitest::Test
12
12
  include TestHelper
13
13
 
14
14
  def setup
15
- Resque::StuckQueue.redis = Redis.new
15
+ Resque::StuckQueue.config[:redis] = Redis.new
16
16
  Resque::StuckQueue.redis.flushall
17
17
  Resque::StuckQueue.config[:abort_on_exception] = true
18
18
  end
@@ -8,7 +8,7 @@ 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::StuckQueue.redis = Redis.new
11
+ Resque::StuckQueue.config[:redis] = Redis.new
12
12
  Resque::StuckQueue.redis.flushall
13
13
  end
14
14
 
@@ -16,13 +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
+ Resque::StuckQueue.config[:redis] = Redis.new
20
20
  Redis.new.flushall
21
21
  end
22
22
 
23
23
  def test_works_with_2_point_oh_do_not_trigger_because_key_is_updated
24
24
 
25
- Resque::StuckQueue.redis = Redis.new
25
+ Resque::StuckQueue.config[:redis] = Redis.new
26
26
 
27
27
  Resque::StuckQueue.config[:heartbeat] = 1
28
28
  Resque::StuckQueue.config[:abort_on_exception] = true
@@ -34,7 +34,7 @@ if !ENV['RESQUE_2'].nil?
34
34
  #binding.pry
35
35
  Resque::StuckQueue.start_in_background
36
36
 
37
- @r2_pid = fork { Resque::StuckQueue.redis = Redis.new ; Resque::Worker.new("*", :graceful_term => true).work ; Process.waitall }
37
+ @r2_pid = fork { Resque::StuckQueue.config[:redis] = Redis.new ; Resque::Worker.new("*", :graceful_term => true).work ; Process.waitall }
38
38
  sleep 10
39
39
 
40
40
  # did not trigger, resque picked up refresh jobs
@@ -12,12 +12,17 @@ class TestResqueStuckQueue < Minitest::Test
12
12
  def setup
13
13
  puts "#{__method__}"
14
14
  # clean previous test runs
15
- Resque::StuckQueue.redis = Redis.new
15
+ Resque::StuckQueue.config[:redis] = Redis.new
16
16
  Resque::StuckQueue.redis.flushall
17
17
  Resque::StuckQueue.config[:heartbeat] = 1 # seconds
18
18
  Resque::StuckQueue.config[:abort_on_exception] = true
19
19
  end
20
20
 
21
+ def test_watcher_and_heartbeat_redis_are_the_same
22
+ # to avoid namespace collisions
23
+ assert_equal Resque::StuckQueue.redis, Resque::StuckQueue::HeartbeatJob.redis
24
+ end
25
+
21
26
  def test_configure_heartbeat_key
22
27
  puts "#{__method__}"
23
28
  assert_nil Resque::StuckQueue.redis.get("it-is-configurable"), "global key should not be set"
@@ -10,7 +10,7 @@ class TestYourOwnRefreshJob < Minitest::Test
10
10
  Resque::StuckQueue.config[:heartbeat] = 1
11
11
  Resque::StuckQueue.config[:abort_on_exception] = true
12
12
  Resque::StuckQueue.config[:heartbeat_job] = nil
13
- Resque::StuckQueue.redis = Redis.new
13
+ Resque::StuckQueue.config[:redis] = Redis.new
14
14
  Resque::StuckQueue.redis.flushall
15
15
  end
16
16
 
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shai Rosenfeld
@@ -40,6 +40,14 @@ dependencies:
40
40
  - *id003
41
41
  type: :development
42
42
  version_requirements: *id004
43
+ - !ruby/object:Gem::Dependency
44
+ name: redis-namespace
45
+ prerelease: false
46
+ requirement: &id005 !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - *id003
49
+ type: :development
50
+ version_requirements: *id005
43
51
  description: where the wild things are. err, when resque gets stuck
44
52
  email:
45
53
  - srosenfeld@engineyard.com