sidekiq-apriori 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3203f8525a25c20fa3a2809bbc431ee64b27ee81
4
+ data.tar.gz: 8dc78be48780cf4eb5c9c010d73fae05f0a24f31
5
+ SHA512:
6
+ metadata.gz: 3227506019efd51481e045ebb7fc613a624687b5c64e351d609847445522babf56956add7474f4e017bb042d5750196a335b504001f11ce170b46affa93e65af
7
+ data.tar.gz: 4b924a010def90fa31bd661c54366e12aee79c58f67a0a6e747b37913f6164b00aed989155713895f55cc68f6ea3a68148dc644a86bea95239b0735e02c3f385
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/README.md CHANGED
@@ -1,4 +1,119 @@
1
1
  sidekiq-apriori
2
2
  ===============
3
-
4
3
  Prioritization Middleware for Sidekiq
4
+
5
+ [![Build Status](https://travis-ci.org/enova/sidekiq-apriori.png)](https://travis-ci.org/enova/sidekiq-apriori)
6
+
7
+ Overview
8
+ --------
9
+
10
+ sidekiq-apriori simplifies dynamic prioritization for sidekiq by supplying a
11
+ simple sidekiq middleware, related active record hooks, & some additional
12
+ argument handling (for ruby 2 users).
13
+
14
+ Installation
15
+ ------------
16
+
17
+ Manual installation is always an option. From the command line:
18
+
19
+ $ gem install sidekiq-priority
20
+
21
+ Or, if you're using bundler, simply include it in your Gemfile:
22
+
23
+ gem 'sidekiq-priority'
24
+
25
+ Priorities
26
+ ----------
27
+
28
+ By default, sidekiq-apriori supports four priorities: immediate, high, nil
29
+ (default), and low. If you would like to use different priorities you can
30
+ add something along these lines to (as an example for you railsy folk) your
31
+ sidekiq initializer:
32
+
33
+ ```ruby
34
+ ## config/initializers/sidekiq.rb
35
+
36
+ Sidekiq::Apriori::PRIORITIES = ['wut', 'huh', 'ok', nil, 'not_even_a_little']
37
+ ```
38
+
39
+ The nil is meaningful insofar as it represents the default priority. Unless you
40
+ want to disallow unset priorities, leave the nil in.
41
+
42
+ sidekiq-apriori is inspired by (a response to?) [sidekiq-priority](https://github.com/socialpandas/sidekiq-priority), in which the
43
+ order of the priorities is important. Contrary to the approach taken by
44
+ sidekiq-priority, sidekiq-apriori uses sidekiq's built in mechanism for
45
+ configuring the order of processing. So, for example, if your sidekiq.yml
46
+ currently looks like this:
47
+
48
+ ```yaml
49
+ ## sidekiq.yml
50
+
51
+ verbose: false
52
+ :pidfile: /tmp/sidekiq.pid
53
+ :concurrency: 5
54
+ :queues:
55
+ - postback
56
+ - background
57
+ ```
58
+
59
+ you might want to change the 'queues' entry to look more like this:
60
+
61
+ ```yaml
62
+ :queues:
63
+ - postback_wut
64
+ - postback_huh
65
+ - postback_ok
66
+ - postback
67
+ - postback_not_even_a_little
68
+ - background
69
+ ```
70
+
71
+ Use
72
+ ---
73
+
74
+ In addition to the use described in the PRIORITIES section, some tooling is
75
+ provided for active record classes with priority as an attribute:
76
+
77
+ ```ruby
78
+ ## app/models/prioritized.rb
79
+
80
+ class Prioritized < ActiveRecord::Base
81
+ include Sidekiq::Apriori::Arb
82
+
83
+ prioritize do
84
+ self.priority = nil unless
85
+ Sidekiq::Apriori::PRIORITIES.include?(self.priority)
86
+
87
+ self.priority = (...)
88
+ end
89
+ end
90
+ ```
91
+
92
+ Alternatively, you can pass a method name to prioritize:
93
+
94
+ ```ruby
95
+ ## app/models/prioritized.rb
96
+
97
+ class Prioritized < ActiveRecord::Base
98
+ include Sidekiq::Apriori::Arb
99
+
100
+ prioritize using: 'some_method'
101
+
102
+ def some_method
103
+ (...)
104
+ end
105
+ end
106
+ ```
107
+
108
+ If you're lucky enough to be using ruby 2, you can save yourself some work by
109
+ including ```Sidekiq::Apriori::Worker``` instead of ```Sidekiq::Worker``` in your
110
+ worker classes. This will have the nifty side effect of saving you the effort of
111
+ changing the definition of the classes' perform method & its invocation.
112
+ ```Sidekiq::Apriori::Worker``` uses ```prepend``` to define a perform which will
113
+ take an optional hash containing a priority designation.
114
+
115
+ License
116
+ -------
117
+
118
+ sidekiq-apriori is released under the MIT License. Please see the [LICENSE](LICENSE)
119
+ file for details.
@@ -1,23 +1,28 @@
1
1
  module Sidekiq::Apriori
2
- def self.included(base)
3
- return unless defined?(ActiveRecord::Base) && base < ActiveRecord::Base
2
+ module Arb
3
+ def self.included(base)
4
4
 
5
- base.extend ClassMethods
5
+ if defined?(ActiveRecord::Base) && base < ActiveRecord::Base
6
+ require 'sidekiq-apriori/arb'
7
+ base.extend ClassMethods
6
8
 
7
- ## Add validation for priority attribute
8
- if base.attribute_names.include?('priority')
9
- base.validates_inclusion_of :priority, :in => PRIORITIES
9
+ ## Add validation for priority attribute
10
+ if base.attribute_names.include?('priority')
11
+ base.validates_inclusion_of :priority, :in => PRIORITIES
12
+ end
13
+ end
10
14
  end
11
- end
12
15
 
13
- module ClassMethods
14
- ## Declarative hook to prioritize instances
15
- def prioritize(options = {}, &block)
16
- method = ( block_given? && [-1, 0].include?(block.arity) ) ?
17
- block : ( options[:using] || options[:with] )
16
+ module ClassMethods
17
+
18
+ ## Declarative hook to prioritize instances
19
+ def prioritize(options = {}, &block)
20
+ method = ( block_given? && [-1, 0].include?(block.arity) ) ?
21
+ block : ( options[:using] || options[:with] )
18
22
 
19
- before_validation method, :on => :create
23
+ before_validation method, :on => :create
24
+ end
20
25
  end
21
- end
22
26
 
27
+ end
23
28
  end
@@ -0,0 +1,7 @@
1
+ require 'sidekiq-apriori/middleware/prioritizer'
2
+
3
+ Sidekiq.configure_client do |config|
4
+ config.client_middleware do |chain|
5
+ chain.add Sidekiq::Apriori::Prioritizer
6
+ end
7
+ end
@@ -1,7 +1,11 @@
1
+ require 'sidekiq-apriori/priorities'
2
+
1
3
  module Sidekiq::Apriori
2
4
  class Prioritizer
3
5
  def call(worker, msg, queue)
4
- priority = msg["args"].try(:last)
6
+ options = msg["args"].last if msg["args"].respond_to?(:last)
7
+ priority = options[:priority] if options.is_a?(Hash) && options.has_key?(:priority)
8
+
5
9
  if priorities.include?(priority)
6
10
  msg["queue"] = queue.to_s.sub(priority_regexp,"_#{priority}")
7
11
  end
@@ -0,0 +1,7 @@
1
+ require 'sidekiq-apriori/middleware/prioritizer'
2
+
3
+ Sidekiq.configure_server do |config|
4
+ config.client_middleware do |chain|
5
+ chain.add Sidekiq::Apriori::Prioritizer
6
+ end
7
+ end
@@ -1,14 +1,3 @@
1
- require 'sidekiq'
2
- require 'sidekiq-apriori/prioritizer'
3
-
4
- Sidekiq.configure_client do |config|
5
- config.client_middleware do |chain|
6
- chain.add Sidekiq::Apriori::Prioritizer
7
- end
8
- end
9
-
10
- Sidekiq.configure_server do |config|
11
- config.client_middleware do |chain|
12
- chain.add Sidekiq::Apriori::Prioritizer
13
- end
14
- end
1
+ require 'sidekiq-apriori/middleware/prioritizer'
2
+ require 'sidekiq-apriori/middleware/client'
3
+ require 'sidekiq-apriori/middleware/server'
@@ -0,0 +1,10 @@
1
+ module Sidekiq
2
+ module Apriori
3
+ PRIORITIES = [
4
+ 'immediate',
5
+ 'high',
6
+ nil,
7
+ 'low'
8
+ ].freeze unless defined?(PRIORITIES)
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Apriori
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,28 @@
1
+ module Sidekiq::Apriori
2
+ module Worker
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include Sidekiq::Worker if defined?(Sidekiq::Worker)
6
+
7
+ version = RUBY_VERSION.split(/\./).map(&:to_i) rescue []
8
+ prepend ClassMethods if version.first > 1
9
+ end
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ def perform(*args)
15
+ retried = false
16
+
17
+ begin
18
+ super(*args)
19
+ rescue ArgumentError => err
20
+ raise err unless
21
+ args.last.is_a?(Hash) && args.last.has_key?(:priority)
22
+
23
+ args = args[0..-2]
24
+ (retried = true ) && retry
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,12 +1,4 @@
1
1
  require 'sidekiq-apriori/version'
2
- require 'sidekiq-apriori/middleware'
3
- require 'sidekiq-apriori/arb.rb'
4
-
5
- module Sidekiq::Apriori
6
- PRIORITIES = [
7
- 'immediate',
8
- 'high',
9
- nil,
10
- 'low'
11
- ].freeze unless defined?(PRIORITIES)
12
- end
2
+ require 'sidekiq-apriori/priorities'
3
+ require 'sidekiq-apriori/middleware/prioritizer'
4
+ require 'sidekiq-apriori/arb'
@@ -20,10 +20,14 @@ Gem::Specification.new do |s|
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
22
 
23
+ s.add_development_dependency "activerecord"
24
+ s.add_development_dependency "fakeredis"
23
25
  s.add_development_dependency "pry"
24
26
  s.add_development_dependency "rake"
25
27
  s.add_development_dependency "rspec"
26
28
  s.add_development_dependency "simplecov"
29
+ s.add_development_dependency "simplecov-rcov"
30
+ s.add_development_dependency "sqlite3"
27
31
 
28
32
  s.add_dependency "sidekiq"
29
33
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'sidekiq-apriori/arb'
3
+
4
+ describe Sidekiq::Apriori::Arb do
5
+
6
+ ## See spec/support/arb.rb for Arb class definition
7
+ require 'support/arb'
8
+
9
+ let(:arb) { Arb.new }
10
+ let(:using_method) { PrioritizedUsingMethod.new }
11
+ let(:using_callable) { PrioritizedUsingCallable.new }
12
+
13
+ it "should validate priorities" do
14
+ arb.priority = "none"
15
+ arb.should be_invalid
16
+
17
+ Sidekiq::Apriori::PRIORITIES.each do |priority|
18
+ arb.priority = priority
19
+ arb.should be_valid
20
+ end
21
+ end
22
+
23
+ it "should attempt prioritization on creation with named prioritizer" do
24
+ using_method.should_receive(:some_method)
25
+ using_method.save
26
+ end
27
+
28
+ it "should attempt prioritization on creation with using a block" do
29
+ using_callable.should_receive(:some_other_method)
30
+ using_callable.save
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'sidekiq-apriori/middleware/prioritizer'
3
+
4
+ describe Sidekiq::Apriori, 'client middleware' do
5
+ before do
6
+ Sidekiq.stub(:server? => false)
7
+
8
+ Sidekiq.configure_client do |config|
9
+ config.client_middleware do |chain|
10
+ chain.remove Sidekiq::Apriori::Prioritizer
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ it "should include Sidekiq::Apriori::Prioritizer in client middleware" do
17
+ Sidekiq.client_middleware.entries.should be_empty
18
+
19
+ (require 'sidekiq-apriori/middleware/client').should be_true
20
+
21
+ Sidekiq.client_middleware.entries.should_not be_empty
22
+ Sidekiq.client_middleware.entries.map(&:klass).
23
+ should be_include(Sidekiq::Apriori::Prioritizer)
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'sidekiq-apriori/middleware/prioritizer'
3
+
4
+ describe Sidekiq::Apriori::Prioritizer do
5
+ subject(:middleware) { Sidekiq::Apriori::Prioritizer.new }
6
+
7
+ let(:queue) { 'foo' }
8
+ let(:message) { {'args' => [1, nil, priority: 'high'], 'queue' => queue } }
9
+
10
+ describe '#call' do
11
+ it 'should respond' do
12
+ middleware.respond_to?(:call).should be_true
13
+ end
14
+
15
+ it 'should require three arguments' do
16
+ expect { middleware.call }.
17
+ to raise_error( ArgumentError,'wrong number of arguments (0 for 3)')
18
+ end
19
+
20
+ it 'should set priority queue' do
21
+ middleware.call(nil, message, queue) {}
22
+ message['queue'].should eql('foo_high')
23
+ end
24
+
25
+ it 'should allow only one priority suffix' do
26
+ message['queue'] = 'foo_low_high_immediate'
27
+ middleware.call(nil, message, queue) {}
28
+ message['queue'].should eql('foo_high')
29
+
30
+ middleware.call(nil, message, queue) {}
31
+ message['queue'].should eql('foo_high')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'sidekiq-apriori/middleware/prioritizer'
3
+
4
+ describe Sidekiq::Apriori, 'server middleware' do
5
+ before do
6
+ Sidekiq.stub(:server? => true)
7
+
8
+ Sidekiq.configure_server do |config|
9
+ config.client_middleware do |chain|
10
+ chain.remove Sidekiq::Apriori::Prioritizer
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ it "should include Sidekiq::Apriori::Prioritizer in client middleware" do
17
+ Sidekiq.client_middleware.entries.should be_empty
18
+
19
+ (require 'sidekiq-apriori/middleware/server').should be_true
20
+
21
+ Sidekiq.client_middleware.entries.should_not be_empty
22
+ Sidekiq.client_middleware.entries.map(&:klass).
23
+ should be_include(Sidekiq::Apriori::Prioritizer)
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'sidekiq-apriori/worker'
3
+
4
+ describe Sidekiq::Apriori::Worker do
5
+ before(:all) do
6
+ class Job
7
+ def perform; end
8
+ include Sidekiq::Apriori::Worker
9
+ end
10
+ end
11
+
12
+ let(:job) { Job.new }
13
+
14
+ ## Checking for ruby 2
15
+ #
16
+ if ( RUBY_VERSION.split(/\./).map(&:to_i) rescue [] ).first > 1
17
+ it "redefines 'perform' to handle an extra argument when that argument has priority information" do
18
+ job.should be_an_instance_of(Job)
19
+ expect { job.perform(priority: "high") }.not_to raise_error
20
+ end
21
+
22
+ it "does not rescue errors with incorrectly formatted priority information" do
23
+ expect { job.perform("high") }.to raise_error(ArgumentError)
24
+ expect { job.perform({}) }.to raise_error(ArgumentError)
25
+ end
26
+ end
27
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'fakeredis/rspec'
2
+ require 'sidekiq'
3
+ require 'sidekiq/testing'
4
+
1
5
  require 'simplecov'
2
6
 
3
7
  SimpleCov.start do
@@ -5,6 +9,35 @@ SimpleCov.start do
5
9
  add_filter "spec"
6
10
  end
7
11
 
8
- require File.expand_path("../../lib/sidekiq-apriori", __FILE__)
12
+ require 'sidekiq-apriori/priorities'
13
+
14
+ redis = { :url => "redis://localhost:6379/0",
15
+ :driver => Redis::Connection::Memory }
9
16
 
10
- require 'support/arb'
17
+ Sidekiq.configure_client { |config| config.redis = redis }
18
+ Sidekiq.configure_server do |config|
19
+ config.redis = redis
20
+
21
+ # require 'support/tracked_fetch'
22
+ # Sidekiq.options[:fetch] = TrackedFetch
23
+ end
24
+
25
+ RSpec.configure do |config|
26
+ config.before(:each) do
27
+ ## Use metadata to determine testing behavior
28
+ ## for queuing.
29
+ Sidekiq::Worker.clear_all
30
+
31
+ case example.metadata[:queuing].to_s
32
+ when 'enable', 'enabled', 'on', 'true'
33
+ Sidekiq::Testing.disable!
34
+ when 'fake', 'mock'
35
+ Sidekiq::Testing.fake!
36
+ when 'inline'
37
+ Sidekiq::Testing.inline!
38
+ else
39
+ defined?(Redis::Connection::Memory) ?
40
+ Sidekiq::Testing.disable! : Sidekiq::Testing.inline!
41
+ end
42
+ end
43
+ end
data/spec/support/arb.rb CHANGED
@@ -1,19 +1,27 @@
1
1
  require 'active_record'
2
+ require 'sidekiq-apriori/arb'
2
3
  require 'sqlite3'
3
4
 
4
5
  ActiveRecord::Base.establish_connection(
5
- :adapter => :sqlite3,
6
- :database => 'spec/support/test.db'
6
+ :adapter => :sqlite3,
7
+ :database => 'spec/support/test.db'
7
8
  )
8
9
 
9
10
  ActiveRecord::Schema.define do
10
- drop_table :arbs
11
-
12
- create_table :arbs do |t|
13
- t.column :priority, :string
14
- end
11
+ drop_table(:arbs) rescue nil
12
+ create_table(:arbs) { |t| t.column(:priority, :string) }
15
13
  end
16
14
 
17
15
  class Arb < ActiveRecord::Base
18
- include Sidekiq::Apriori
16
+ include Sidekiq::Apriori::Arb
17
+ end
18
+
19
+ class PrioritizedUsingMethod < Arb
20
+ prioritize using: :some_method
21
+ end
22
+
23
+ class PrioritizedUsingCallable < Arb
24
+ prioritize do
25
+ self.some_other_method
26
+ end
19
27
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-apriori
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Blake Thomas
@@ -10,86 +9,132 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-11-28 00:00:00.000000000 Z
12
+ date: 2013-12-01 00:00:00.000000000 Z
14
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: fakeredis
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
15
42
  - !ruby/object:Gem::Dependency
16
43
  name: pry
17
44
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
45
  requirements:
20
- - - ! '>='
46
+ - - '>='
21
47
  - !ruby/object:Gem::Version
22
48
  version: '0'
23
49
  type: :development
24
50
  prerelease: false
25
51
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
52
  requirements:
28
- - - ! '>='
53
+ - - '>='
29
54
  - !ruby/object:Gem::Version
30
55
  version: '0'
31
56
  - !ruby/object:Gem::Dependency
32
57
  name: rake
33
58
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
59
  requirements:
36
- - - ! '>='
60
+ - - '>='
37
61
  - !ruby/object:Gem::Version
38
62
  version: '0'
39
63
  type: :development
40
64
  prerelease: false
41
65
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
66
  requirements:
44
- - - ! '>='
67
+ - - '>='
45
68
  - !ruby/object:Gem::Version
46
69
  version: '0'
47
70
  - !ruby/object:Gem::Dependency
48
71
  name: rspec
49
72
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
73
  requirements:
52
- - - ! '>='
74
+ - - '>='
53
75
  - !ruby/object:Gem::Version
54
76
  version: '0'
55
77
  type: :development
56
78
  prerelease: false
57
79
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
80
  requirements:
60
- - - ! '>='
81
+ - - '>='
61
82
  - !ruby/object:Gem::Version
62
83
  version: '0'
63
84
  - !ruby/object:Gem::Dependency
64
85
  name: simplecov
65
86
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
87
  requirements:
68
- - - ! '>='
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov-rcov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: sqlite3
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
69
117
  - !ruby/object:Gem::Version
70
118
  version: '0'
71
119
  type: :development
72
120
  prerelease: false
73
121
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
122
  requirements:
76
- - - ! '>='
123
+ - - '>='
77
124
  - !ruby/object:Gem::Version
78
125
  version: '0'
79
126
  - !ruby/object:Gem::Dependency
80
127
  name: sidekiq
81
128
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
129
  requirements:
84
- - - ! '>='
130
+ - - '>='
85
131
  - !ruby/object:Gem::Version
86
132
  version: '0'
87
133
  type: :runtime
88
134
  prerelease: false
89
135
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
136
  requirements:
92
- - - ! '>='
137
+ - - '>='
93
138
  - !ruby/object:Gem::Version
94
139
  version: '0'
95
140
  description: Prioritization middleware for Sidekiq
@@ -101,6 +146,7 @@ extra_rdoc_files: []
101
146
  files:
102
147
  - .gitignore
103
148
  - .rspec
149
+ - .ruby-version
104
150
  - .simplecov
105
151
  - .travis.yml
106
152
  - Gemfile
@@ -110,39 +156,49 @@ files:
110
156
  - lib/sidekiq-apriori.rb
111
157
  - lib/sidekiq-apriori/arb.rb
112
158
  - lib/sidekiq-apriori/middleware.rb
113
- - lib/sidekiq-apriori/prioritizer.rb
159
+ - lib/sidekiq-apriori/middleware/client.rb
160
+ - lib/sidekiq-apriori/middleware/prioritizer.rb
161
+ - lib/sidekiq-apriori/middleware/server.rb
162
+ - lib/sidekiq-apriori/priorities.rb
114
163
  - lib/sidekiq-apriori/version.rb
164
+ - lib/sidekiq-apriori/worker.rb
115
165
  - sidekiq-apriori.gemspec
116
- - spec/sidekiq-apriori_spec.rb
166
+ - spec/sidekiq-apriori/arb_spec.rb
167
+ - spec/sidekiq-apriori/middleware/client_spec.rb
168
+ - spec/sidekiq-apriori/middleware/prioritizer_spec.rb
169
+ - spec/sidekiq-apriori/middleware/server_spec.rb
170
+ - spec/sidekiq-apriori/worker_spec.rb
117
171
  - spec/spec_helper.rb
118
172
  - spec/support/arb.rb
119
173
  homepage: https://github.com/bwthomas/sidekiq-apriori
120
174
  licenses:
121
175
  - MIT
176
+ metadata: {}
122
177
  post_install_message:
123
178
  rdoc_options: []
124
179
  require_paths:
125
180
  - lib
126
181
  required_ruby_version: !ruby/object:Gem::Requirement
127
- none: false
128
182
  requirements:
129
- - - ! '>='
183
+ - - '>='
130
184
  - !ruby/object:Gem::Version
131
185
  version: '0'
132
186
  required_rubygems_version: !ruby/object:Gem::Requirement
133
- none: false
134
187
  requirements:
135
- - - ! '>='
188
+ - - '>='
136
189
  - !ruby/object:Gem::Version
137
190
  version: '0'
138
191
  requirements: []
139
192
  rubyforge_project: nowarning
140
- rubygems_version: 1.8.23
193
+ rubygems_version: 2.0.3
141
194
  signing_key:
142
- specification_version: 3
195
+ specification_version: 4
143
196
  summary: Prioritization Middleware for Sidekiq
144
197
  test_files:
145
- - spec/sidekiq-apriori_spec.rb
198
+ - spec/sidekiq-apriori/arb_spec.rb
199
+ - spec/sidekiq-apriori/middleware/client_spec.rb
200
+ - spec/sidekiq-apriori/middleware/prioritizer_spec.rb
201
+ - spec/sidekiq-apriori/middleware/server_spec.rb
202
+ - spec/sidekiq-apriori/worker_spec.rb
146
203
  - spec/spec_helper.rb
147
204
  - spec/support/arb.rb
148
- has_rdoc:
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Sidekiq::Apriori do
4
- before(:all) do
5
- ## See spec/support/arb.rb for Arb class definition
6
- class Prioritized < Arb
7
- prioritize using: :some_method
8
- end
9
- end
10
-
11
- let(:arb) { Arb.new }
12
- let(:prioritized) { Prioritized.new }
13
-
14
- it "should validate priorities" do
15
- arb.priority = "none"
16
- arb.should be_invalid
17
-
18
- Sidekiq::Apriori::PRIORITIES.each do |priority|
19
- arb.priority = priority
20
- arb.should be_valid
21
- end
22
- end
23
-
24
- it "should attempt prioritization on creation with named prioritizer" do
25
- prioritized.should_receive(:some_method)
26
- prioritized.save
27
- end
28
-
29
- describe Sidekiq::Apriori::Prioritizer do
30
- subject(:middleware) { Sidekiq::Apriori::Prioritizer.new }
31
-
32
- let(:message) { {'args' => [1, nil, 'high'], 'queue' => 'foo'} }
33
- let(:queue) { 'foo' }
34
-
35
- describe '#call' do
36
- it 'should respond' do
37
- middleware.respond_to?(:call).should be_true
38
- end
39
-
40
- it 'should require three arguments' do
41
- expect { middleware.call }.
42
- to raise_error( ArgumentError,'wrong number of arguments (0 for 3)')
43
- end
44
-
45
- it 'should set priority queue' do
46
- middleware.call(nil, message, queue) {}
47
- message['queue'].should eql('foo_high')
48
- end
49
-
50
- it 'should allow only one priority suffix' do
51
- message['queue'] = 'foo_low_high_immediate'
52
- middleware.call(nil, message, queue) {}
53
- message['queue'].should eql('foo_high')
54
-
55
- middleware.call(nil, message, queue) {}
56
- message['queue'].should eql('foo_high')
57
- end
58
- end
59
- end
60
- end