sidekiq-limit_fetch 2.0 → 2.0.1

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: 674ddce501d3c50f771a21a1e7546513af0a2669
4
- data.tar.gz: f6bd2050d3e7eea9b599fc1989680b77c3e7de85
3
+ metadata.gz: 4db872c28ebde76d915d79b0a0bdbdbcf9859b38
4
+ data.tar.gz: 9c6104f1869c2979a9e908f01ca6035d3319e134
5
5
  SHA512:
6
- metadata.gz: e6e72377703afe1307173b6174c41bae6e4d819222431c061b2d16339a678e45968c3b51101f4a96e11253f8df17910b76a343870f1a306e322dafe7aab84e89
7
- data.tar.gz: fc59c7b2b8c779556914a2d4aeea8282354df0a2e19154f99513a02ff8d013642b4e68fce46959d2b311a0a30d5c41bbc999d7a5a55cb7a949a8255cb9a1d716
6
+ metadata.gz: 28706d72d599cc68bb431edafdbfb886a4438b92e165257ae5fe862aee16899d530a5c96fa42c75a2f7f8155105e6d0219bdbfb91493d1bfd7c49eff26dcf605
7
+ data.tar.gz: 4dc6225e29e2aa26a64867f9dda5eee538000e443e713da38bd3b4d124aa5bfafbf563ec72214e6df120e90af30af5a7d5cdac014426196b398adfb90e637e2f
data/Rakefile CHANGED
@@ -2,4 +2,11 @@ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new
5
- task default: :spec
5
+
6
+ task :default do
7
+ rspec = Rake::Task[:spec]
8
+ rspec.invoke
9
+ ENV['namespace'] = 'namespace'
10
+ rspec.reenable
11
+ rspec.invoke
12
+ end
@@ -8,7 +8,7 @@ limit = ARGV.shift
8
8
  if limit
9
9
  limit = nil if limit == 'nil'
10
10
 
11
- $:.unshift File.expand_path './lib'
11
+ $:.unshift File.expand_path '../lib'
12
12
  require 'sidekiq-limit_fetch'
13
13
  Sidekiq::Queue['inline'].limit = limit
14
14
  Sidekiq.redis {|it| it.del 'limit_fetch:probed:inline' }
@@ -2,11 +2,11 @@ module Sidekiq::LimitFetch::Global
2
2
  module Selector
3
3
  extend self
4
4
 
5
- def acquire(queues)
5
+ def acquire(queues, namespace)
6
6
  redis_eval :acquire, [namespace, uuid, queues]
7
7
  end
8
8
 
9
- def release(queues)
9
+ def release(queues, namespace)
10
10
  redis_eval :release, [namespace, uuid, queues]
11
11
  end
12
12
 
@@ -22,13 +22,6 @@ module Sidekiq::LimitFetch::Global
22
22
 
23
23
  private
24
24
 
25
- def namespace
26
- @namespace ||= begin
27
- namespace = Sidekiq.options[:namespace]
28
- namespace + ':' if namespace
29
- end
30
- end
31
-
32
25
  def redis_eval(script_name, args)
33
26
  Sidekiq.redis do |it|
34
27
  begin
@@ -1,7 +1,6 @@
1
1
  module Sidekiq::LimitFetch::Global
2
2
  class Semaphore
3
- extend Forwardable
4
- def_delegator Sidekiq, :redis
3
+ include Sidekiq::LimitFetch::Redis
5
4
 
6
5
  PREFIX = 'limit_fetch'
7
6
 
@@ -19,7 +18,7 @@ module Sidekiq::LimitFetch::Global
19
18
  end
20
19
 
21
20
  def acquire
22
- Selector.acquire([@name]).size > 0
21
+ Selector.acquire([@name], determine_namespace).size > 0
23
22
  end
24
23
 
25
24
  def release
@@ -3,7 +3,9 @@ class Sidekiq::LimitFetch
3
3
  THREAD_KEY = :acquired_queues
4
4
 
5
5
  def initialize(options)
6
- @queues = options[:queues]
6
+ @queues = options[:queues]
7
+ @namespace = options[:namespace]
8
+
7
9
  options[:strict] ? strict_order! : weighted_order!
8
10
 
9
11
  set_limits options[:limits]
@@ -11,7 +13,7 @@ class Sidekiq::LimitFetch
11
13
  end
12
14
 
13
15
  def acquire
14
- selector.acquire(ordered_queues)
16
+ selector.acquire(ordered_queues, @namespace)
15
17
  .tap {|it| save it }
16
18
  .map {|it| "queue:#{it}" }
17
19
  end
@@ -19,7 +21,7 @@ class Sidekiq::LimitFetch
19
21
  def release_except(full_name)
20
22
  queues = restore
21
23
  queues.delete full_name[/queue:(.*)/, 1] if full_name
22
- selector.release queues
24
+ selector.release queues, @namespace
23
25
  end
24
26
 
25
27
  private
@@ -1,13 +1,27 @@
1
1
  module Sidekiq::LimitFetch::Redis
2
+ extend self
3
+
2
4
  # prevent blocking of fetcher
3
5
  # more bullet-proof and faster (O_O)
4
6
  # than using Celluloid::IO
5
- def redis
6
- Sidekiq.redis do |redis|
7
+ def nonblocking_redis
8
+ redis do |redis|
7
9
  begin
8
10
  Celluloid::Future.new { yield redis }.value
9
11
  end
10
12
  end
11
13
  rescue Celluloid::Task::TerminatedError
12
14
  end
15
+
16
+ def redis
17
+ Sidekiq.redis {|it| yield it }
18
+ end
19
+
20
+ def determine_namespace
21
+ redis do |it|
22
+ if it.respond_to?(:namespace) and it.namespace
23
+ it.namespace + ':'
24
+ end
25
+ end
26
+ end
13
27
  end
@@ -21,7 +21,7 @@ class Sidekiq::LimitFetch
21
21
 
22
22
  def initialize(options)
23
23
  Global::Monitor.start!
24
- @queues = Queues.new options
24
+ @queues = Queues.new options.merge(namespace: determine_namespace)
25
25
  end
26
26
 
27
27
  def retrieve_work
@@ -39,6 +39,6 @@ class Sidekiq::LimitFetch
39
39
 
40
40
  def redis_brpop(*args)
41
41
  return if args.size < 2
42
- redis {|it| it.brpop *args }
42
+ nonblocking_redis {|it| it.brpop *args }
43
43
  end
44
44
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'sidekiq-limit_fetch'
3
- gem.version = '2.0'
3
+ gem.version = '2.0.1'
4
4
  gem.authors = 'brainopia'
5
5
  gem.email = 'brainopia@evilmartians.com'
6
6
  gem.summary = 'Sidekiq strategy to support queue limits'
@@ -12,7 +12,8 @@ describe Sidekiq::LimitFetch::Queues do
12
12
  { queues: queues,
13
13
  limits: limits,
14
14
  strict: strict,
15
- blocking: blocking }
15
+ blocking: blocking,
16
+ namespace: Sidekiq::LimitFetch::Redis.determine_namespace }
16
17
  end
17
18
 
18
19
  it 'should acquire queues' do
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,9 @@ require 'sidekiq/limit_fetch'
2
2
  require 'celluloid/autostart'
3
3
  require 'sidekiq/fetch'
4
4
 
5
+ Sidekiq.logger = nil
6
+ Sidekiq.redis = { namespace: ENV['namespace'] }
7
+
5
8
  RSpec.configure do |config|
6
9
  config.before :each do
7
10
  Sidekiq.redis do |it|
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'
4
+ version: 2.0.1
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-17 00:00:00.000000000 Z
11
+ date: 2013-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq