resque-fairly 1.0.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.
checksums.yaml ADDED
@@ -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
data/Gemfile.lock ADDED
@@ -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
@@ -8,6 +8,44 @@ distributed across the set of queues with pending jobs fairly. This
8
8
  results in a much more predictable mean time to handling for jobs in
9
9
  queues that are not the first in the list.
10
10
 
11
+ Weighted Priorites
12
+ ----
13
+
14
+ resque-fairly works by sorting the queues randomly before assigning
15
+ the next queue on the list to a worker. You can add weights to
16
+ your various queues to alter their likelihood of being selected, by
17
+ using /priorities/. The priorities select queues by regular expression.
18
+
19
+ Example:
20
+
21
+ Resque::Plugins::Fairly.prioritize(/^a/, 2)
22
+
23
+ The above will prioritize queues whose names start with 'a' to
24
+ be selected twice as often as the default.
25
+
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.
48
+
11
49
  Note on Patches/Pull Requests
12
50
  ----
13
51
 
@@ -23,4 +61,4 @@ Note on Patches/Pull Requests
23
61
  Copyright
24
62
  ----
25
63
 
26
- Copyright (c) 2010 Peter Williams. See LICENSE for details.
64
+ Copyright (c) 2009 OpenLogic, Inc. See LICENSE for details.
data/Rakefile CHANGED
@@ -9,10 +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_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"]
16
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
16
  end
18
17
  Jeweler::GemcutterTasks.new
@@ -35,13 +34,3 @@ end
35
34
  task :spec => :check_dependencies
36
35
 
37
36
  task :default => :spec
38
-
39
- require 'rake/rdoctask'
40
- Rake::RDocTask.new do |rdoc|
41
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
-
43
- rdoc.rdoc_dir = 'rdoc'
44
- rdoc.title = "resque-fairly #{version}"
45
- rdoc.rdoc_files.include('README*')
46
- rdoc.rdoc_files.include('lib/**/*.rb')
47
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.4.1
@@ -2,6 +2,41 @@ require 'resque/worker'
2
2
 
3
3
  module Resque::Plugins
4
4
  module Fairly
5
+ # Define an 'unfair' priority multiplier to queues whose name
6
+ # matches the specified regex
7
+ def self.prioritize(regex, weight)
8
+ raise ArgumentError, '`regex` must be a regular expression' unless Regexp === regex
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
17
+ end
18
+
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
+ }
38
+ end
39
+
5
40
  # Returns a list of queues to use when searching for a job. A
6
41
  # splat ("*") means you want every queue
7
42
  #
@@ -9,8 +44,20 @@ module Resque::Plugins
9
44
  # with every call. This prevents any particular queue for being
10
45
  # starved. Workers will process queues in a random order each
11
46
  # time the poll for new work.
47
+ #
48
+ # If priorities have been established, the randomness of the order
49
+ # will be weighted according to the multipliers
12
50
  def queues_randomly_ordered
13
- queues_alpha_ordered.sort_by{rand}
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
14
61
  end
15
62
 
16
63
  def self.included(klass)
@@ -19,9 +66,35 @@ module Resque::Plugins
19
66
  alias_method :queues, :queues_randomly_ordered
20
67
  end
21
68
  end
22
- end
23
69
 
24
- Resque::Worker.send(:include, Fairly)
25
- end
70
+ private
26
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
27
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
data/lib/resque-fairly.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ gem 'resque', :version => '~> 1.0'
2
3
  require 'resque'
3
4
 
4
5
  require File.expand_path('resque/plugins/fairly', File.dirname(__FILE__))
@@ -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
+
@@ -5,14 +5,42 @@ describe Resque::Plugins::Fairly do
5
5
  worker = Resque::Worker.new('a','b')
6
6
 
7
7
  srand(2)
8
- worker.queues.should == ['b', 'a']
8
+ worker.queues.should == ['a', 'b']
9
9
  end
10
10
 
11
11
  it "changes Resque::Worker#queues to return queues in a random order (rand seeded w/ 1)" do
12
12
  worker = Resque::Worker.new('a','b')
13
13
 
14
14
  srand(1)
15
- worker.queues.should == ['a', 'b']
15
+ worker.queues.should == ['b', 'a']
16
+ end
17
+
18
+ it "changes Resque::Worker#queues to return queues in a weighted random order" do
19
+ worker = Resque::Worker.new('a','b')
20
+ Resque::Plugins::Fairly.reset.prioritize(/a/, 2)
21
+
22
+ as, bs = [], []
23
+ 1.upto 100 do
24
+ arr = worker.queues
25
+ as << arr if arr.first == 'a'
26
+ bs << arr if arr.first == 'b'
27
+ end
28
+
29
+ as.size.should == 66
30
+ bs.size.should == 34
16
31
  end
17
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
18
46
  end
@@ -1,7 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "ResqueFairly" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
6
- end
7
4
  end
metadata CHANGED
@@ -1,91 +1,116 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: resque-fairly
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 0
9
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.1
10
5
  platform: ruby
11
- authors:
6
+ authors:
7
+ - D Cameron Mauch
12
8
  - Peter Williams
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-08-22 00:00:00 -06:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2015-01-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: resque
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
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
21
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
22
50
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 2
30
- - 9
31
- 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'
32
63
  type: :development
33
- version_requirements: *id001
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
34
70
  description: |
35
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.
36
-
37
- email: pezra@barelyenough.org
72
+ email: cameron.mauch@roguewave.com
38
73
  executables: []
39
-
40
74
  extensions: []
41
-
42
- extra_rdoc_files:
75
+ extra_rdoc_files:
43
76
  - LICENSE
44
77
  - README.md
45
- files:
46
- - .document
47
- - .gitignore
78
+ files:
79
+ - ".document"
80
+ - Gemfile
81
+ - Gemfile.lock
48
82
  - LICENSE
49
83
  - README.md
50
84
  - Rakefile
51
85
  - VERSION
52
86
  - lib/resque-fairly.rb
53
87
  - lib/resque/plugins/fairly.rb
88
+ - resque-fairly.gemspec
54
89
  - spec/resque-fairly_spec.rb
55
90
  - spec/resque/plugins/fairly_spec.rb
56
91
  - spec/spec.opts
57
92
  - spec/spec_helper.rb
58
- has_rdoc: true
59
- homepage: http://github.com/pezra/resque-fairly
93
+ homepage: http://github.com/openlogic/resque-fairly
60
94
  licenses: []
61
-
95
+ metadata: {}
62
96
  post_install_message:
63
- rdoc_options:
64
- - --charset=UTF-8
65
- require_paths:
97
+ rdoc_options: []
98
+ require_paths:
66
99
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
68
- requirements:
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
69
102
  - - ">="
70
- - !ruby/object:Gem::Version
71
- segments:
72
- - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
75
- requirements:
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
76
107
  - - ">="
77
- - !ruby/object:Gem::Version
78
- segments:
79
- - 0
80
- version: "0"
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
81
110
  requirements: []
82
-
83
111
  rubyforge_project:
84
- rubygems_version: 1.3.6
112
+ rubygems_version: 2.2.2
85
113
  signing_key:
86
- specification_version: 3
114
+ specification_version: 4
87
115
  summary: Fair queue processing for Resque
88
- test_files:
89
- - spec/resque/plugins/fairly_spec.rb
90
- - spec/resque-fairly_spec.rb
91
- - spec/spec_helper.rb
116
+ test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC