resque-fairly 1.1.0 → 1.4.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ce973bff34f5c4c1e5213ada0bab47e012cba6e
4
+ data.tar.gz: e92698b7cc17c8e50df5ed0a002fe9cff1c0bf98
5
+ SHA512:
6
+ metadata.gz: 1b93c49dcd73b9f21f00082a0885bb05b4559dc1912b67b2c60868e464cf505415ae915688d00fc519d70c5dac194bf5afaf5ce5037a984cb9bc206d7a5d9c1d
7
+ data.tar.gz: 408037f85ab7196707b6d39e6e0d7278a4968800eaf038df9e58bb79b4535c0365aeec13fe20137ffabdca66d1f8ee194c417a1e31ac3a8989f701cdf1997c78
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "resque", "~> 1.0"
4
+
5
+ group :development do
6
+ gem "rspec", "~> 1.0"
7
+ gem "bundler", "~> 1.0"
8
+ gem "jeweler", "~> 2.0"
9
+ end
@@ -0,0 +1,77 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ faraday (0.9.1)
9
+ multipart-post (>= 1.2, < 3)
10
+ git (1.2.9.1)
11
+ github_api (0.12.2)
12
+ addressable (~> 2.3)
13
+ descendants_tracker (~> 0.0.4)
14
+ faraday (~> 0.8, < 0.10)
15
+ hashie (>= 3.3)
16
+ multi_json (>= 1.7.5, < 2.0)
17
+ nokogiri (~> 1.6.3)
18
+ oauth2
19
+ hashie (3.3.2)
20
+ highline (1.6.21)
21
+ jeweler (2.0.1)
22
+ builder
23
+ bundler (>= 1.0)
24
+ git (>= 1.2.5)
25
+ github_api
26
+ highline (>= 1.6.15)
27
+ nokogiri (>= 1.5.10)
28
+ rake
29
+ rdoc
30
+ json (1.8.2)
31
+ jwt (1.2.0)
32
+ mini_portile (0.6.2)
33
+ mono_logger (1.1.0)
34
+ multi_json (1.10.1)
35
+ multi_xml (0.5.5)
36
+ multipart-post (2.0.0)
37
+ nokogiri (1.6.5)
38
+ mini_portile (~> 0.6.0)
39
+ oauth2 (1.0.0)
40
+ faraday (>= 0.8, < 0.10)
41
+ jwt (~> 1.0)
42
+ multi_json (~> 1.3)
43
+ multi_xml (~> 0.5)
44
+ rack (~> 1.2)
45
+ rack (1.6.0)
46
+ rack-protection (1.5.3)
47
+ rack
48
+ rake (10.4.2)
49
+ rdoc (4.2.0)
50
+ json (~> 1.4)
51
+ redis (3.2.0)
52
+ redis-namespace (1.5.1)
53
+ redis (~> 3.0, >= 3.0.4)
54
+ resque (1.25.2)
55
+ mono_logger (~> 1.0)
56
+ multi_json (~> 1.0)
57
+ redis-namespace (~> 1.3)
58
+ sinatra (>= 0.9.2)
59
+ vegas (~> 0.1.2)
60
+ rspec (1.3.2)
61
+ sinatra (1.4.5)
62
+ rack (~> 1.4)
63
+ rack-protection (~> 1.4)
64
+ tilt (~> 1.3, >= 1.3.4)
65
+ thread_safe (0.3.4)
66
+ tilt (1.4.1)
67
+ vegas (0.1.11)
68
+ rack (>= 1.0.0)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ bundler (~> 1.0)
75
+ jeweler (~> 2.0)
76
+ resque (~> 1.0)
77
+ rspec (~> 1.0)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Peter Williams
1
+ Copyright (c) 2009 OpenLogic, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -23,8 +23,28 @@ Example:
23
23
  The above will prioritize queues whose names start with 'a' to
24
24
  be selected twice as often as the default.
25
25
 
26
- You can use floating point numbers, 0 and/or negative numbers as
27
- the multiplier.
26
+ You can use any floating point number as the multiplier. If a queue is
27
+ matched by more than one priority, the final weight will be the product
28
+ of all the matching weights.
29
+
30
+ Only and Except filters
31
+ ----
32
+
33
+ Also filters the queues based on one or more regular expressions to
34
+ include and/or exclude the matching queues. Note: All these methods
35
+ are also chainable.
36
+
37
+ Examples:
38
+
39
+ Resque::Plugins::Fairly.only(/foo/).except(/foobar/)
40
+
41
+ The above will return a randomized list of queues which contain the
42
+ text 'foo', but not the text 'foobar'
43
+
44
+ Reset
45
+ ----
46
+
47
+ Clears all priorities and only and except filters.
28
48
 
29
49
  Note on Patches/Pull Requests
30
50
  ----
@@ -41,4 +61,4 @@ Note on Patches/Pull Requests
41
61
  Copyright
42
62
  ----
43
63
 
44
- Copyright (c) 2010 Peter Williams. See LICENSE for details.
64
+ Copyright (c) 2009 OpenLogic, Inc. See LICENSE for details.
data/Rakefile CHANGED
@@ -9,11 +9,9 @@ begin
9
9
  gem.description = <<DESC
10
10
  Normally resque processes queues in a fixed order. This can lead to jobs in queues at the end of the list not getting process for very long periods. resque-fairly provides a mechanism where by workers are distributed across the set of queues with pending jobs fairly. This results in a much more predictable mean time to handling for jobs in queues that are not the first in the list.
11
11
  DESC
12
- gem.email = "pezra@barelyenough.org"
13
- gem.homepage = "http://github.com/pezra/resque-fairly"
14
- gem.authors = ["Peter Williams"]
15
- gem.add_dependency "resque", "~>1.0"
16
- gem.add_development_dependency "rspec", ">= 1.2.9"
12
+ gem.email = "cameron.mauch@roguewave.com"
13
+ gem.homepage = "http://github.com/openlogic/resque-fairly"
14
+ gem.authors = ["D Cameron Mauch", "Peter Williams"]
17
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
16
  end
19
17
  Jeweler::GemcutterTasks.new
@@ -36,13 +34,3 @@ end
36
34
  task :spec => :check_dependencies
37
35
 
38
36
  task :default => :spec
39
-
40
- require 'rake/rdoctask'
41
- Rake::RDocTask.new do |rdoc|
42
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
-
44
- rdoc.rdoc_dir = 'rdoc'
45
- rdoc.title = "resque-fairly #{version}"
46
- rdoc.rdoc_files.include('README*')
47
- rdoc.rdoc_files.include('lib/**/*.rb')
48
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.4.1
@@ -4,13 +4,37 @@ module Resque::Plugins
4
4
  module Fairly
5
5
  # Define an 'unfair' priority multiplier to queues whose name
6
6
  # matches the specified regex
7
- def self.prioritize(regex, multiplier)
7
+ def self.prioritize(regex, weight)
8
8
  raise ArgumentError, '`regex` must be a regular expression' unless Regexp === regex
9
- priorities << [regex, multiplier]
9
+ options[:priority] << {regex: regex, weight: weight}
10
+ self
11
+ end
12
+
13
+ def self.only(regex)
14
+ raise ArgumentError, '`regex` must be a regular expression' unless Regexp === regex
15
+ options[:only] << regex
16
+ self
10
17
  end
11
18
 
12
- def self.priorities
13
- @priorities ||= []
19
+ def self.except(regex)
20
+ raise ArgumentError, '`regex` must be a regular expression' unless Regexp === regex
21
+ options[:except] << regex
22
+ self
23
+ end
24
+
25
+ def self.reset(list = [:priority, :only, :except])
26
+ list.each do |option|
27
+ options[option] = []
28
+ end
29
+ self
30
+ end
31
+
32
+ def self.options
33
+ @options ||= {
34
+ priority: [],
35
+ only: [],
36
+ except: []
37
+ }
14
38
  end
15
39
 
16
40
  # Returns a list of queues to use when searching for a job. A
@@ -24,10 +48,16 @@ module Resque::Plugins
24
48
  # If priorities have been established, the randomness of the order
25
49
  # will be weighted according to the multipliers
26
50
  def queues_randomly_ordered
27
- queues_alpha_ordered.sort_by do |queue|
28
- multiplier = Fairly.priorities.select{|p|p[0] === queue}[0][1] rescue 1
29
- rand * multiplier
30
- end.reverse
51
+ list = queues_alpha_ordered
52
+
53
+ list = select_only_queues(list) if Fairly.options[:only].any?
54
+ list = reject_except_queues(list) if Fairly.options[:except].any?
55
+
56
+ list = list.sort_by do |item|
57
+ weights = [rand] + priority_weights(item)
58
+ weight = weights.reduce(&:*)
59
+ end
60
+ list = list.reverse
31
61
  end
32
62
 
33
63
  def self.included(klass)
@@ -36,9 +66,35 @@ module Resque::Plugins
36
66
  alias_method :queues, :queues_randomly_ordered
37
67
  end
38
68
  end
39
- end
40
69
 
41
- Resque::Worker.send(:include, Fairly)
42
- end
70
+ private
43
71
 
72
+ def select_only_queues(list)
73
+ list.select do |item|
74
+ Fairly.options[:only].any? do |regex|
75
+ regex === item
76
+ end
77
+ end
78
+ end
44
79
 
80
+ def reject_except_queues(list)
81
+ list.reject do |item|
82
+ Fairly.options[:except].any? do |regex|
83
+ regex === item
84
+ end
85
+ end
86
+ end
87
+
88
+ def priority_weights(item)
89
+ priorities = Fairly.options[:priority].select do |priority|
90
+ priority[:regex] === item
91
+ end
92
+
93
+ weights = priorities.map do |priority|
94
+ priority[:weight]
95
+ end
96
+ end
97
+ end
98
+
99
+ Resque::Worker.send(:include, Fairly)
100
+ end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: resque-fairly 1.4.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "resque-fairly"
9
+ s.version = "1.4.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["D Cameron Mauch", "Peter Williams"]
14
+ s.date = "2015-01-19"
15
+ s.description = "Normally resque processes queues in a fixed order. This can lead to jobs in queues at the end of the list not getting process for very long periods. resque-fairly provides a mechanism where by workers are distributed across the set of queues with pending jobs fairly. This results in a much more predictable mean time to handling for jobs in queues that are not the first in the list.\n"
16
+ s.email = "cameron.mauch@roguewave.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/resque-fairly.rb",
30
+ "lib/resque/plugins/fairly.rb",
31
+ "resque-fairly.gemspec",
32
+ "spec/resque-fairly_spec.rb",
33
+ "spec/resque/plugins/fairly_spec.rb",
34
+ "spec/spec.opts",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = "http://github.com/openlogic/resque-fairly"
38
+ s.rubygems_version = "2.2.2"
39
+ s.summary = "Fair queue processing for Resque"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 4
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<resque>, ["~> 1.0"])
46
+ s.add_development_dependency(%q<rspec>, ["~> 1.0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
49
+ else
50
+ s.add_dependency(%q<resque>, ["~> 1.0"])
51
+ s.add_dependency(%q<rspec>, ["~> 1.0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<resque>, ["~> 1.0"])
57
+ s.add_dependency(%q<rspec>, ["~> 1.0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
60
+ end
61
+ end
62
+
@@ -17,10 +17,10 @@ describe Resque::Plugins::Fairly do
17
17
 
18
18
  it "changes Resque::Worker#queues to return queues in a weighted random order" do
19
19
  worker = Resque::Worker.new('a','b')
20
- Resque::Plugins::Fairly.prioritize(/a/, 2)
20
+ Resque::Plugins::Fairly.reset.prioritize(/a/, 2)
21
21
 
22
22
  as, bs = [], []
23
- 1.upto 100 do
23
+ 1.upto 100 do
24
24
  arr = worker.queues
25
25
  as << arr if arr.first == 'a'
26
26
  bs << arr if arr.first == 'b'
@@ -29,4 +29,18 @@ describe Resque::Plugins::Fairly do
29
29
  as.size.should == 66
30
30
  bs.size.should == 34
31
31
  end
32
+
33
+ it "changes Resque::Worker#queues to return queues with only queues only" do
34
+ worker = Resque::Worker.new('d','e','f')
35
+ Resque::Plugins::Fairly.reset.only(/e/)
36
+
37
+ worker.queues.should == ['e']
38
+ end
39
+
40
+ it "changes Resque::Worker#queues to return queues without except queues" do
41
+ worker = Resque::Worker.new('g','h','i')
42
+ Resque::Plugins::Fairly.reset.except(/h/)
43
+
44
+ worker.queues.should =~ ['g', 'i']
45
+ end
32
46
  end
metadata CHANGED
@@ -1,112 +1,116 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: resque-fairly
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 1
9
- - 0
10
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
7
+ - D Cameron Mauch
13
8
  - Peter Williams
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-03-04 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2015-01-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: resque
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
- version: "1.0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
34
21
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
37
29
  name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.0'
49
+ type: :development
38
50
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 13
45
- segments:
46
- - 1
47
- - 2
48
- - 9
49
- version: 1.2.9
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: jeweler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
50
63
  type: :development
51
- version_requirements: *id002
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
52
70
  description: |
53
71
  Normally resque processes queues in a fixed order. This can lead to jobs in queues at the end of the list not getting process for very long periods. resque-fairly provides a mechanism where by workers are distributed across the set of queues with pending jobs fairly. This results in a much more predictable mean time to handling for jobs in queues that are not the first in the list.
54
-
55
- email: pezra@barelyenough.org
72
+ email: cameron.mauch@roguewave.com
56
73
  executables: []
57
-
58
74
  extensions: []
59
-
60
- extra_rdoc_files:
75
+ extra_rdoc_files:
61
76
  - LICENSE
62
77
  - README.md
63
- files:
64
- - .document
78
+ files:
79
+ - ".document"
80
+ - Gemfile
81
+ - Gemfile.lock
65
82
  - LICENSE
66
83
  - README.md
67
84
  - Rakefile
68
85
  - VERSION
69
86
  - lib/resque-fairly.rb
70
87
  - lib/resque/plugins/fairly.rb
88
+ - resque-fairly.gemspec
71
89
  - spec/resque-fairly_spec.rb
72
90
  - spec/resque/plugins/fairly_spec.rb
73
91
  - spec/spec.opts
74
92
  - spec/spec_helper.rb
75
- has_rdoc: true
76
- homepage: http://github.com/pezra/resque-fairly
93
+ homepage: http://github.com/openlogic/resque-fairly
77
94
  licenses: []
78
-
95
+ metadata: {}
79
96
  post_install_message:
80
97
  rdoc_options: []
81
-
82
- require_paths:
98
+ require_paths:
83
99
  - lib
84
- required_ruby_version: !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
87
102
  - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
93
- required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
96
107
  - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
102
110
  requirements: []
103
-
104
111
  rubyforge_project:
105
- rubygems_version: 1.3.7
112
+ rubygems_version: 2.2.2
106
113
  signing_key:
107
- specification_version: 3
114
+ specification_version: 4
108
115
  summary: Fair queue processing for Resque
109
- test_files:
110
- - spec/resque-fairly_spec.rb
111
- - spec/resque/plugins/fairly_spec.rb
112
- - spec/spec_helper.rb
116
+ test_files: []