resque-fairly 1.0.1 → 1.1.0

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.
data/README.md CHANGED
@@ -8,6 +8,24 @@ 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 floating point numbers, 0 and/or negative numbers as
27
+ the multiplier.
28
+
11
29
  Note on Patches/Pull Requests
12
30
  ----
13
31
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -2,6 +2,17 @@ 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, multiplier)
8
+ raise ArgumentError, '`regex` must be a regular expression' unless Regexp === regex
9
+ priorities << [regex, multiplier]
10
+ end
11
+
12
+ def self.priorities
13
+ @priorities ||= []
14
+ end
15
+
5
16
  # Returns a list of queues to use when searching for a job. A
6
17
  # splat ("*") means you want every queue
7
18
  #
@@ -9,8 +20,14 @@ module Resque::Plugins
9
20
  # with every call. This prevents any particular queue for being
10
21
  # starved. Workers will process queues in a random order each
11
22
  # time the poll for new work.
23
+ #
24
+ # If priorities have been established, the randomness of the order
25
+ # will be weighted according to the multipliers
12
26
  def queues_randomly_ordered
13
- queues_alpha_ordered.sort_by{rand}
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
14
31
  end
15
32
 
16
33
  def self.included(klass)
@@ -5,14 +5,28 @@ 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
16
  end
17
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.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
31
+ end
18
32
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-fairly
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 0
8
8
  - 1
9
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Peter Williams
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-23 00:00:00 -06:00
18
+ date: 2011-03-04 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: resque
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 15
27
30
  segments:
28
31
  - 1
29
32
  - 0
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: rspec
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ">="
39
43
  - !ruby/object:Gem::Version
44
+ hash: 13
40
45
  segments:
41
46
  - 1
42
47
  - 2
@@ -57,7 +62,6 @@ extra_rdoc_files:
57
62
  - README.md
58
63
  files:
59
64
  - .document
60
- - .gitignore
61
65
  - LICENSE
62
66
  - README.md
63
67
  - Rakefile
@@ -73,32 +77,36 @@ homepage: http://github.com/pezra/resque-fairly
73
77
  licenses: []
74
78
 
75
79
  post_install_message:
76
- rdoc_options:
77
- - --charset=UTF-8
80
+ rdoc_options: []
81
+
78
82
  require_paths:
79
83
  - lib
80
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
81
86
  requirements:
82
87
  - - ">="
83
88
  - !ruby/object:Gem::Version
89
+ hash: 3
84
90
  segments:
85
91
  - 0
86
92
  version: "0"
87
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
88
95
  requirements:
89
96
  - - ">="
90
97
  - !ruby/object:Gem::Version
98
+ hash: 3
91
99
  segments:
92
100
  - 0
93
101
  version: "0"
94
102
  requirements: []
95
103
 
96
104
  rubyforge_project:
97
- rubygems_version: 1.3.6
105
+ rubygems_version: 1.3.7
98
106
  signing_key:
99
107
  specification_version: 3
100
108
  summary: Fair queue processing for Resque
101
109
  test_files:
102
- - spec/resque/plugins/fairly_spec.rb
103
110
  - spec/resque-fairly_spec.rb
111
+ - spec/resque/plugins/fairly_spec.rb
104
112
  - spec/spec_helper.rb
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