1
0
Fork 0
mirror of https://github.com/deanpcmad/sidekiq-limit_fetch.git synced 2022-11-09 13:54:36 -05:00

Use global mode by default

This commit is contained in:
brainopia 2013-04-25 14:19:49 +04:00
parent 9267d8e0b8
commit 74f3c0be01
9 changed files with 39 additions and 48 deletions

View file

@ -58,25 +58,6 @@ will be preserved.
Sidekiq::Queue['name'].unpause # allows workers to use the queue
```
### Multiple processes
Limits are applied per process. In case you have several worker
processes and want to have global locks between them, you'll need to
enable global mode by setting global option, eg:
```yaml
:global: true
```
or
```ruby
Sidekiq.options[:global] = true
```
*Note:* if you want to change limits from a rails console you also need
to use a global mode since it's a different from a worker process.
### Blocking queue mode
If you use strict queue ordering (it will be used if you don't specify queue weights)

View file

@ -16,7 +16,7 @@ module Sidekiq
end
def mode
Sidekiq.options[:global] ? LimitFetch::Global : LimitFetch::Local
Sidekiq.options[:local] ? LimitFetch::Local : LimitFetch::Global
end
end
end

View file

@ -19,7 +19,7 @@ class Sidekiq::LimitFetch
end
def initialize(options)
Global::Monitor.start! if options[:global]
Global::Monitor.start! unless options[:local]
@queues = Queues.new options
end

View file

@ -7,7 +7,7 @@ class Sidekiq::LimitFetch
@queues = options[:queues]
options[:strict] ? strict_order! : weighted_order!
set_selector options[:global]
set_selector options[:local]
set_limits options[:limits]
set_blocks options[:blocking]
end
@ -26,8 +26,8 @@ class Sidekiq::LimitFetch
private
def set_selector(global)
@selector = global ? Global::Selector : Local::Selector
def set_selector(local)
@selector = local ? Local::Selector : Global::Selector
end
def set_limits(limits)

View file

@ -88,12 +88,12 @@ describe Sidekiq::Queue do
end
context 'global' do
before(:all) { Sidekiq.options[:global] = true }
before(:all) { Sidekiq.options[:local] = false }
it_behaves_like :lock
end
context 'local' do
before(:all) { Sidekiq.options[:global] = false }
before(:all) { Sidekiq.options[:local] = true }
it_behaves_like :lock
end
end

View file

@ -1,13 +1,23 @@
require 'spec_helper'
describe Sidekiq::LimitFetch::Global::Monitor do
let(:global) { true }
let(:monitor) { described_class.start! ttl, timeout }
let(:ttl) { 1 }
let(:queue) { Sidekiq::Queue[name] }
let(:name) { 'default' }
before :each do
# namespaces = [
# described_class::PROCESSOR_NAMESPACE,
# described_class::HEARTBEAT_NAMESPACE
# ]
# Sidekiq.redis do |it|
# namespaces.flat_map {|namespace|
# it.keys(namespace + '*')
# }.each {|key| it.del key }
# end
monitor
end

View file

@ -3,17 +3,17 @@ require 'spec_helper'
describe Sidekiq::LimitFetch::Queues do
subject { described_class.new options }
let(:queues) { %w[queue1 queue2] }
let(:limits) {{ 'queue1' => 3 }}
let(:strict) { true }
let(:global) { false }
let(:blocking) { nil }
let(:queues) { %w[queue1 queue2] }
let(:limits) {{ 'queue1' => 3 }}
let(:strict) { true }
let(:local) {}
let(:blocking) {}
let(:options) do
{ queues: queues,
limits: limits,
strict: strict,
global: global,
{ queues: queues,
limits: limits,
strict: strict,
local: local,
blocking: blocking }
end
@ -83,20 +83,20 @@ describe Sidekiq::LimitFetch::Queues do
end
end
context 'without global flag' do
context 'without local flag' do
it_should_behave_like :selector
it 'without global flag should be local' do
subject.selector.should == Sidekiq::LimitFetch::Local::Selector
it 'without local flag should be global' do
subject.selector.should == Sidekiq::LimitFetch::Global::Selector
end
end
context 'with global flag' do
let(:global) { true }
context 'with local flag' do
let(:local) { true }
it_should_behave_like :selector
it 'should use global selector' do
subject.selector.should == Sidekiq::LimitFetch::Global::Selector
it 'should use local selector' do
subject.selector.should == Sidekiq::LimitFetch::Local::Selector
end
end

View file

@ -11,7 +11,7 @@ describe Sidekiq::LimitFetch do
end
subject { described_class.new options }
let(:options) {{ queues: queues, limits: limits, global: global }}
let(:options) {{ queues: queues, limits: limits, local: local }}
let(:queues) { %w(queue1 queue1 queue2 queue2) }
let(:limits) {{ 'queue1' => 1, 'queue2' => 2 }}
@ -36,12 +36,12 @@ describe Sidekiq::LimitFetch do
end
context 'global' do
let(:global) { true }
let(:local) { false }
it_behaves_like :strategy
end
context 'local' do
let(:global) { false }
let(:local) { true }
it_behaves_like :strategy
end
end

View file

@ -3,8 +3,8 @@ require 'sidekiq/limit_fetch'
RSpec.configure do |config|
config.before :each do
Sidekiq::Queue.instance_variable_set :@instances, {}
Sidekiq.options[:global] = defined?(global) ? global : nil
Sidekiq.options[:local] = defined?(local) ? local : nil
Sidekiq.redis do |it|
clean_redis = ->(queue) do
it.del "limit_fetch:limit:#{queue}"