resque-queue-priority 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,14 +31,35 @@ module Resque
31
31
  next
32
32
  end
33
33
 
34
- patstr = bucket_pattern.gsub(/\*/, ".*")
35
- pattern = /^#{patstr}$/
36
- bucket_queues, remaining = all_queues.partition {|q| q =~ pattern }
37
-
34
+ bucket_queues, remaining = [], []
35
+
36
+ patterns = bucket_pattern.split(',')
37
+ patterns.each do |pattern|
38
+ pattern = pattern.strip
39
+
40
+ if pattern[0] == '!'
41
+ negated = true
42
+ pattern = pattern[1..-1]
43
+ end
44
+
45
+ patstr = pattern.gsub(/\*/, ".*")
46
+ pattern = /^#{patstr}$/
47
+
48
+
49
+ if negated
50
+ bucket_queues -= bucket_queues.grep(pattern)
51
+ else
52
+ bucket_queues.concat(all_queues.grep(pattern))
53
+ end
54
+
55
+ end
56
+
57
+ bucket_queues.uniq!
38
58
  bucket_queues.shuffle! if fairly
39
- all_queues = remaining
40
-
59
+ all_queues = all_queues - bucket_queues
60
+
41
61
  result << bucket_queues
62
+
42
63
  end
43
64
 
44
65
  # insert the remaining queues at the position the default item was at (or last)
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module QueuePriority
4
- VERSION = "0.5.3"
4
+ VERSION = "0.6.0"
5
5
  end
6
6
  end
7
7
  end
@@ -112,6 +112,34 @@ describe "Queue Priority" do
112
112
  worker.queues.should == ["high_x", "high_y", "foo", "superhigh_z"]
113
113
  end
114
114
 
115
+ it "should prioritize simple wildcard pattern with correct matching" do
116
+ Resque.priority_buckets = [{'pattern' => '*high*', 'fairly' => false},
117
+ {'pattern' => 'default', 'fairly' => false}]
118
+ worker = Resque::Worker.new("*")
119
+ worker.queues.should == ["high_x", "high_y", "superhigh_z", "foo"]
120
+ end
121
+
122
+ it "should prioritize negation patterns" do
123
+ Resque.priority_buckets = [{'pattern' => 'high*,!high_x', 'fairly' => false},
124
+ {'pattern' => 'default', 'fairly' => false}]
125
+ worker = Resque::Worker.new("*")
126
+ worker.queues.should == ["high_y", "foo", "high_x", "superhigh_z"]
127
+ end
128
+
129
+ it "should not be affected by standalone negation patterns" do
130
+ Resque.priority_buckets = [{'pattern' => '!high_x', 'fairly' => false},
131
+ {'pattern' => 'default', 'fairly' => false}]
132
+ worker = Resque::Worker.new("*")
133
+ worker.queues.should == ["foo", "high_x", "high_y", "superhigh_z"]
134
+ end
135
+
136
+ it "should allow multiple inclusive patterns" do
137
+ Resque.priority_buckets = [{'pattern' => 'high_x, superhigh*', 'fairly' => false},
138
+ {'pattern' => 'default', 'fairly' => false}]
139
+ worker = Resque::Worker.new("*")
140
+ worker.queues.should == ["high_x", "superhigh_z", "foo", "high_y"]
141
+ end
142
+
115
143
  it "should prioritize fully inclusive wildcard pattern" do
116
144
  Resque.priority_buckets = [{'pattern' => '*high*', 'fairly' => false},
117
145
  {'pattern' => 'default', 'fairly' => false}]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-queue-priority
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-14 00:00:00.000000000Z
12
+ date: 2011-12-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: resque
16
- requirement: &2253842400 !ruby/object:Gem::Requirement
16
+ requirement: &2154438400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.10'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2253842400
24
+ version_requirements: *2154438400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2253841980 !ruby/object:Gem::Requirement
27
+ requirement: &2154437980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2253841980
35
+ version_requirements: *2154437980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2253841440 !ruby/object:Gem::Requirement
38
+ requirement: &2154437440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.5'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2253841440
46
+ version_requirements: *2154437440
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack-test
49
- requirement: &2253840940 !ruby/object:Gem::Requirement
49
+ requirement: &2154436940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.5.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2253840940
57
+ version_requirements: *2154436940
58
58
  description: A resque plugin for specifying the priority between queues that workers
59
59
  use to determine what to work on next
60
60
  email: