sidekiq-limit_fetch 1.7 → 2.0

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: 4c5121de39e03363b90b64633028f65ed5cf6983
4
- data.tar.gz: 935a28cd47181070776e71fe60db08165cab2ffe
3
+ metadata.gz: 674ddce501d3c50f771a21a1e7546513af0a2669
4
+ data.tar.gz: f6bd2050d3e7eea9b599fc1989680b77c3e7de85
5
5
  SHA512:
6
- metadata.gz: 09f48f0e5dce160c809b4fdad660f35c0fe2ac27ee3f6d850d094fc2e995adc70c3915cefb2ff4bc3a3aea2785c4f2a5edf3ca65c0692aea923dfbcd8ccdb2f4
7
- data.tar.gz: a4d226be6b1df6fad9ab438dfd60e8e29235c89540f209c3399c5dd3ef24781184e653af3ae7cdbc67d08104f3a8fa16d6a44084ca36ecf3780d14e024579d78
6
+ metadata.gz: e6e72377703afe1307173b6174c41bae6e4d819222431c061b2d16339a678e45968c3b51101f4a96e11253f8df17910b76a343870f1a306e322dafe7aab84e89
7
+ data.tar.gz: fc59c7b2b8c779556914a2d4aeea8282354df0a2e19154f99513a02ff8d013642b4e68fce46959d2b311a0a30d5c41bbc999d7a5a55cb7a949a8255cb9a1d716
data/README.md CHANGED
@@ -14,6 +14,10 @@ Add this line to your application's Gemfile:
14
14
 
15
15
  gem 'sidekiq-limit_fetch'
16
16
 
17
+ ### Requirements
18
+
19
+ redis 2.6 or newer
20
+
17
21
  ## Usage
18
22
 
19
23
  ### Limits
@@ -0,0 +1,49 @@
1
+ require 'benchmark'
2
+ require 'sidekiq/cli'
3
+
4
+ total = (ARGV.shift || 50).to_i
5
+ concurrency = ARGV.shift || 1
6
+ limit = ARGV.shift
7
+
8
+ if limit
9
+ limit = nil if limit == 'nil'
10
+
11
+ $:.unshift File.expand_path './lib'
12
+ require 'sidekiq-limit_fetch'
13
+ Sidekiq::Queue['inline'].limit = limit
14
+ Sidekiq.redis {|it| it.del 'limit_fetch:probed:inline' }
15
+ end
16
+
17
+ Sidekiq::Queue.new('inline').clear
18
+
19
+ class FastJob
20
+ include Sidekiq::Worker
21
+ sidekiq_options queue: :inline
22
+
23
+ def perform(i)
24
+ puts "job N#{i} is finished"
25
+ end
26
+ end
27
+
28
+ class FinishJob
29
+ include Sidekiq::Worker
30
+ sidekiq_options queue: :inline
31
+
32
+ def perform
33
+ Process.kill 'INT', 0
34
+ end
35
+ end
36
+
37
+ total.times {|i| FastJob.perform_async i+1 }
38
+ FinishJob.perform_async
39
+
40
+ Sidekiq::CLI.instance.tap do |cli|
41
+ %w(validate! boot_system).each {|stub| cli.define_singleton_method(stub) {}}
42
+ cli.parse ['-q inline', '-q other', "-c #{concurrency}"]
43
+ puts Benchmark.measure {
44
+ begin
45
+ cli.run
46
+ rescue Exception
47
+ end
48
+ }
49
+ end
@@ -0,0 +1 @@
1
+ require_relative 'sidekiq/limit_fetch'
@@ -4,6 +4,7 @@ require 'forwardable'
4
4
  class Sidekiq::LimitFetch
5
5
  autoload :UnitOfWork, 'sidekiq/limit_fetch/unit_of_work'
6
6
 
7
+ require_relative 'limit_fetch/redis'
7
8
  require_relative 'limit_fetch/singleton'
8
9
  require_relative 'limit_fetch/queues'
9
10
  require_relative 'limit_fetch/global/semaphore'
@@ -11,6 +12,7 @@ class Sidekiq::LimitFetch
11
12
  require_relative 'limit_fetch/global/monitor'
12
13
  require_relative 'extensions/queue'
13
14
 
15
+ include Redis
14
16
  Sidekiq.options[:fetch] = self
15
17
 
16
18
  def self.bulk_requeue(jobs)
@@ -30,13 +32,13 @@ class Sidekiq::LimitFetch
30
32
  private
31
33
 
32
34
  def fetch_message
33
- queue, _ = redis_blpop *@queues.acquire, Sidekiq::Fetcher::TIMEOUT
35
+ queue, _ = redis_brpop *@queues.acquire, Sidekiq::Fetcher::TIMEOUT
34
36
  ensure
35
37
  @queues.release_except queue
36
38
  end
37
39
 
38
- def redis_blpop(*args)
40
+ def redis_brpop(*args)
39
41
  return if args.size < 2
40
- Sidekiq.redis {|it| it.blpop *args }
42
+ redis {|it| it.brpop *args }
41
43
  end
42
44
  end
@@ -0,0 +1,13 @@
1
+ module Sidekiq::LimitFetch::Redis
2
+ # prevent blocking of fetcher
3
+ # more bullet-proof and faster (O_O)
4
+ # than using Celluloid::IO
5
+ def redis
6
+ Sidekiq.redis do |redis|
7
+ begin
8
+ Celluloid::Future.new { yield redis }.value
9
+ end
10
+ end
11
+ rescue Celluloid::Task::TerminatedError
12
+ end
13
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'sidekiq-limit_fetch'
3
- gem.version = '1.7'
3
+ gem.version = '2.0'
4
4
  gem.authors = 'brainopia'
5
5
  gem.email = 'brainopia@evilmartians.com'
6
6
  gem.summary = 'Sidekiq strategy to support queue limits'
@@ -4,8 +4,8 @@ describe Sidekiq::LimitFetch do
4
4
  before :each do
5
5
  Sidekiq.redis do |it|
6
6
  it.del 'queue:queue1'
7
- it.rpush 'queue:queue1', 'task1'
8
- it.rpush 'queue:queue1', 'task2'
7
+ it.lpush 'queue:queue1', 'task1'
8
+ it.lpush 'queue:queue1', 'task2'
9
9
  it.expire 'queue:queue1', 30
10
10
  end
11
11
  end
@@ -30,7 +30,7 @@ describe Sidekiq::LimitFetch do
30
30
  Sidekiq::Queue['queue2'].busy.should == 0
31
31
 
32
32
  work = subject.retrieve_work
33
- work.message.should == 'task2'
33
+ work.message.should == 'task1'
34
34
 
35
35
  Sidekiq::Queue['queue1'].busy.should == 1
36
36
  Sidekiq::Queue['queue2'].busy.should == 0
@@ -42,6 +42,6 @@ describe Sidekiq::LimitFetch do
42
42
  Sidekiq::Queue['queue2'].busy.should == 0
43
43
 
44
44
  work = subject.retrieve_work
45
- work.message.should == 'task1'
45
+ work.message.should == 'task2'
46
46
  end
47
47
  end
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: '1.7'
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - brainopia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-22 00:00:00.000000000 Z
11
+ date: 2013-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -72,12 +72,15 @@ files:
72
72
  - LICENSE.txt
73
73
  - README.md
74
74
  - Rakefile
75
+ - benchmarks/compare.rb
76
+ - lib/sidekiq-limit_fetch.rb
75
77
  - lib/sidekiq/extensions/queue.rb
76
78
  - lib/sidekiq/limit_fetch.rb
77
79
  - lib/sidekiq/limit_fetch/global/monitor.rb
78
80
  - lib/sidekiq/limit_fetch/global/selector.rb
79
81
  - lib/sidekiq/limit_fetch/global/semaphore.rb
80
82
  - lib/sidekiq/limit_fetch/queues.rb
83
+ - lib/sidekiq/limit_fetch/redis.rb
81
84
  - lib/sidekiq/limit_fetch/singleton.rb
82
85
  - lib/sidekiq/limit_fetch/unit_of_work.rb
83
86
  - sidekiq-limit_fetch.gemspec
@@ -106,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
109
  version: '0'
107
110
  requirements: []
108
111
  rubyforge_project:
109
- rubygems_version: 2.0.3
112
+ rubygems_version: 2.0.2
110
113
  signing_key:
111
114
  specification_version: 4
112
115
  summary: Sidekiq strategy to support queue limits
@@ -117,4 +120,3 @@ test_files:
117
120
  - spec/sidekiq/limit_fetch/semaphore_spec.rb
118
121
  - spec/sidekiq/limit_fetch_spec.rb
119
122
  - spec/spec_helper.rb
120
- has_rdoc: