sidekiq-limit_fetch 2.0.1 → 2.0.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
2
  SHA1:
3
- metadata.gz: 4db872c28ebde76d915d79b0a0bdbdbcf9859b38
4
- data.tar.gz: 9c6104f1869c2979a9e908f01ca6035d3319e134
3
+ metadata.gz: 6b6b646adb74d487fd895406ea53cda04b0ab98e
4
+ data.tar.gz: b28348a416bc854f47482b2cde8bd34cd2446e17
5
5
  SHA512:
6
- metadata.gz: 28706d72d599cc68bb431edafdbfb886a4438b92e165257ae5fe862aee16899d530a5c96fa42c75a2f7f8155105e6d0219bdbfb91493d1bfd7c49eff26dcf605
7
- data.tar.gz: 4dc6225e29e2aa26a64867f9dda5eee538000e443e713da38bd3b4d124aa5bfafbf563ec72214e6df120e90af30af5a7d5cdac014426196b398adfb90e637e2f
6
+ metadata.gz: 27c6e9b79001dce26c0aaac71ffbe5d70787018a1c51bb0538ba3707f2a4db51c9b65f94fabd67cb399a934ad38b876ba567d5629441462c66a9615eddf13c25
7
+ data.tar.gz: be6b48c15f8d66d561d2d07fde2903e4f4acb87c72b7f7b50a383f2cebd42e0b342f0bf980e18e1917e1997fedbb424679c9f2cdb547ebd592f925fbeab5adab
data/README.md CHANGED
@@ -18,6 +18,12 @@ Add this line to your application's Gemfile:
18
18
 
19
19
  redis 2.6 or newer
20
20
 
21
+ ```
22
+ heroku uses redis 2.4 by default
23
+ to update version you need to contact their support:
24
+ https://devcenter.heroku.com/articles/redistogo#redis-26
25
+ ```
26
+
21
27
  ## Usage
22
28
 
23
29
  ### Limits
File without changes
@@ -1,6 +1,7 @@
1
1
  module Sidekiq
2
2
  class Queue
3
3
  extend LimitFetch::Singleton, Forwardable
4
+ attr_reader :rname
4
5
 
5
6
  def_delegators :lock,
6
7
  :limit, :limit=,
@@ -10,7 +11,8 @@ module Sidekiq
10
11
  :paused?, :blocking?,
11
12
  :unblocked, :block_except,
12
13
  :probed, :busy,
13
- :increase_busy, :decrease_busy
14
+ :increase_busy, :decrease_busy,
15
+ :local_busy?
14
16
 
15
17
  def lock
16
18
  @lock ||= LimitFetch::Global::Semaphore.new name
@@ -15,8 +15,8 @@ class Sidekiq::LimitFetch
15
15
  include Redis
16
16
  Sidekiq.options[:fetch] = self
17
17
 
18
- def self.bulk_requeue(jobs)
19
- Sidekiq::BasicFetch.bulk_requeue jobs
18
+ def self.bulk_requeue(*args)
19
+ Sidekiq::BasicFetch.bulk_requeue *args
20
20
  end
21
21
 
22
22
  def initialize(options)
@@ -39,6 +39,16 @@ class Sidekiq::LimitFetch
39
39
 
40
40
  def redis_brpop(*args)
41
41
  return if args.size < 2
42
- nonblocking_redis {|it| it.brpop *args }
42
+ query = -> redis { redis.brpop *args }
43
+
44
+ if busy_local_queues.any? {|queue| not args.include? queue.rname }
45
+ nonblocking_redis(&query)
46
+ else
47
+ redis(&query)
48
+ end
49
+ end
50
+
51
+ def busy_local_queues
52
+ Sidekiq::Queue.instances.select(&:local_busy?)
43
53
  end
44
54
  end
@@ -4,8 +4,12 @@ module Sidekiq::LimitFetch::Global
4
4
 
5
5
  PREFIX = 'limit_fetch'
6
6
 
7
+ attr_reader :local_busy
8
+
7
9
  def initialize(name)
8
10
  @name = name
11
+ @lock = Mutex.new
12
+ @local_busy = 0
9
13
  end
10
14
 
11
15
  def limit
@@ -30,10 +34,12 @@ module Sidekiq::LimitFetch::Global
30
34
  end
31
35
 
32
36
  def increase_busy
37
+ increase_local_busy
33
38
  redis {|it| it.rpush "#{PREFIX}:busy:#@name", Selector.uuid }
34
39
  end
35
40
 
36
41
  def decrease_busy
42
+ decrease_local_busy
37
43
  redis {|it| it.lrem "#{PREFIX}:busy:#@name", 1, Selector.uuid }
38
44
  end
39
45
 
@@ -69,5 +75,17 @@ module Sidekiq::LimitFetch::Global
69
75
  def blocking?
70
76
  redis {|it| it.get "#{PREFIX}:block:#@name" }
71
77
  end
78
+
79
+ def increase_local_busy
80
+ @lock.synchronize { @local_busy += 1 }
81
+ end
82
+
83
+ def decrease_local_busy
84
+ @lock.synchronize { @local_busy -= 1 }
85
+ end
86
+
87
+ def local_busy?
88
+ @local_busy > 0
89
+ end
72
90
  end
73
91
  end
@@ -8,4 +8,8 @@ module Sidekiq::LimitFetch::Singleton
8
8
  end
9
9
 
10
10
  alias [] new
11
+
12
+ def instances
13
+ @instances.values
14
+ end
11
15
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'sidekiq-limit_fetch'
3
- gem.version = '2.0.1'
3
+ gem.version = '2.0.2'
4
4
  gem.authors = 'brainopia'
5
5
  gem.email = 'brainopia@evilmartians.com'
6
6
  gem.summary = 'Sidekiq strategy to support queue limits'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-limit_fetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - brainopia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-18 00:00:00.000000000 Z
11
+ date: 2013-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -72,7 +72,7 @@ files:
72
72
  - LICENSE.txt
73
73
  - README.md
74
74
  - Rakefile
75
- - benchmarks/compare.rb
75
+ - bench/compare.rb
76
76
  - lib/sidekiq-limit_fetch.rb
77
77
  - lib/sidekiq/extensions/queue.rb
78
78
  - lib/sidekiq/limit_fetch.rb