sidekiq-dynamic-queues 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use jruby-1.7.2
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.5.1
2
+ -----
3
+
4
+ use jruby for dev <bc793df> [Matt Conway]
5
+ hack to translate queues from sidekiq cli since it doesn't allow special characters <ba7b99a> [Matt Conway]
6
+
1
7
  0.5.0
2
8
  -----
3
9
 
@@ -11,7 +11,7 @@ module Sidekiq
11
11
 
12
12
  def initialize(options)
13
13
  super
14
- @dynamic_queues = options[:queues]
14
+ @dynamic_queues = self.class.translate_from_cli(*options[:queues])
15
15
  end
16
16
 
17
17
  # overriding Sidekiq::BasicFetch#queues_cmd
@@ -77,6 +77,13 @@ module Sidekiq
77
77
 
78
78
  return matched_queues.collect { |q| "queue:#{q}" }.uniq.sort
79
79
  end
80
+
81
+
82
+ def self.translate_from_cli(*queues)
83
+ queues.collect do |queue|
84
+ queue.gsub('.star.', '*').gsub('.at.', '@').gsub('.not.', '!')
85
+ end
86
+ end
80
87
 
81
88
  end
82
89
 
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module DynamicQueues
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
data/spec/queues_spec.rb CHANGED
@@ -3,6 +3,7 @@ require "spec_helper"
3
3
  describe "Dynamic Queues" do
4
4
 
5
5
  include Sidekiq::DynamicQueues::Attributes
6
+ Fetch = Sidekiq::DynamicQueues::Fetch
6
7
 
7
8
  def watch_queues(*queues)
8
9
  Sidekiq.redis do |r|
@@ -16,28 +17,6 @@ describe "Dynamic Queues" do
16
17
  Sidekiq.redis {|r| r.flushall }
17
18
  end
18
19
 
19
- context "basic behavior still works" do
20
-
21
- it "can work on different queues" do
22
- SomeJob.perform_async(1)
23
- run_queues("default")
24
- SomeJob.result.should eq [1]
25
- enqueue_on("other", SomeJob, 2)
26
- run_queues("other")
27
- SomeJob.result.should eq [2]
28
- end
29
-
30
- it "can work on multiple queues" do
31
- SomeJob.perform_async(1)
32
- run_queues("other", "default")
33
- SomeJob.result.should eq [1]
34
- enqueue_on("other", SomeJob, 2)
35
- run_queues("default", "other")
36
- SomeJob.result.should eq [2]
37
- end
38
-
39
- end
40
-
41
20
  context "attributes" do
42
21
 
43
22
  it "should always have a fallback pattern" do
@@ -72,12 +51,42 @@ describe "Dynamic Queues" do
72
51
  get_dynamic_queues.should == {'default' => ['*']}
73
52
  end
74
53
 
54
+ end
55
+
56
+ context "#translate_from_cli" do
57
+
58
+ it "passes through reqular queue name" do
59
+ translated = Fetch.translate_from_cli("foo", "baz.bar", "bo_o", "bu-m")
60
+ translated.should eq ["foo", "baz.bar", "bo_o", "bu-m"]
61
+ end
62
+
63
+ it "translates *" do
64
+ translated = Fetch.translate_from_cli(".star.", ".star.foo",
65
+ "foo.star.", "f.star.o")
66
+ translated.should eq ["*", "*foo", "foo*", "f*o"]
67
+ end
68
+
69
+ it "translates !" do
70
+ translated = Fetch.translate_from_cli(".not.", ".not.foo",
71
+ "foo.not.", "f.not.o")
72
+ translated.should eq ["!", "!foo", "foo!", "f!o"]
73
+ end
74
+
75
+ it "translates @" do
76
+ translated = Fetch.translate_from_cli(".at.", ".at.foo",
77
+ "foo.at.", "f.at.o")
78
+ translated.should eq ["@", "@foo", "foo@", "f@o"]
79
+ end
80
+
81
+ it "translates multiple" do
82
+ translated = Fetch.translate_from_cli(".not..star.", ".not..at.foo")
83
+ translated.should eq ["!*", "!@foo"]
84
+ end
75
85
 
76
86
  end
77
87
 
78
88
  context "basic queue patterns" do
79
89
 
80
- Fetch = Sidekiq::DynamicQueues::Fetch
81
90
  SFTO = Sidekiq::Fetcher::TIMEOUT
82
91
 
83
92
  before(:each) do
@@ -195,4 +204,44 @@ describe "Dynamic Queues" do
195
204
 
196
205
  end
197
206
 
207
+ context "integration" do
208
+ before(:all) do
209
+ Sidekiq.options[:fetch] = Sidekiq::DynamicQueues::Fetch
210
+ Sidekiq.options[:queue_refresh_timeout] = 0.01
211
+ end
212
+
213
+ it "does use the correct fetch strategy" do
214
+ Sidekiq::Fetcher.strategy.should eq Sidekiq::DynamicQueues::Fetch
215
+ end
216
+
217
+ it "can work on different queues" do
218
+ SomeJob.perform_async(1)
219
+ run_queues("default")
220
+ SomeJob.result.should eq [1]
221
+ enqueue_on("other", SomeJob, 2)
222
+ run_queues("other")
223
+ SomeJob.result.should eq [2]
224
+
225
+ end
226
+
227
+ it "can work on multiple queues" do
228
+ SomeJob.perform_async(1)
229
+ run_queues("other", "default")
230
+ SomeJob.result.should eq [1]
231
+ enqueue_on("other", SomeJob, 2)
232
+ run_queues("default", "other")
233
+ SomeJob.result.should eq [2]
234
+ end
235
+
236
+ it "finds work on dynamic queue that doesn't exist till after" do
237
+ watch_queues(*%w[default])
238
+ manager = run_queues("*", :async => true)
239
+ sleep 0.2
240
+ enqueue_on("other", SomeJob, 1)
241
+ manager.wait(:shutdown)
242
+ SomeJob.result.should eq [1]
243
+ end
244
+
245
+ end
246
+
198
247
  end
data/spec/spec_helper.rb CHANGED
@@ -70,15 +70,24 @@ def enqueue_on(queue, job_class, *job_args)
70
70
  end
71
71
 
72
72
  def run_queues(*queues)
73
+ options = queues.last.is_a?(Hash) ? queues.pop : {}
74
+ options = {:async => false, :job_count => 1}.merge(options)
75
+
73
76
  Sidekiq::Fetcher.instance_eval { @done = false }
74
77
  manager = Sidekiq::Manager.new({:queues=>queues, :concurrency=>1, :timeout=>1})
75
78
 
79
+ job_count = 0
76
80
  manager.when_done do
77
- manager.async.stop(:shutdown => true, :timeout => 0)
81
+ job_count += 1
82
+ yield if block_given?
83
+ if job_count >= options[:job_count].to_i
84
+ manager.stop(:shutdown => true, :timeout => 0)
85
+ end
78
86
  end
79
- manager.async.start
87
+ manager.start
80
88
 
81
- manager.wait(:shutdown)
89
+ manager.wait(:shutdown) unless options[:async]
90
+ manager
82
91
  end
83
92
 
84
93
 
metadata CHANGED
@@ -1,122 +1,128 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-dynamic-queues
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
- prerelease:
4
+ prerelease:
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Conway
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
16
+ version_requirements: !ruby/object:Gem::Requirement
18
17
  requirements:
19
- - - ~>
18
+ - - "~>"
20
19
  - !ruby/object:Gem::Version
21
20
  version: '2.9'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
21
  none: false
22
+ requirement: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '2.9'
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
32
+ version_requirements: !ruby/object:Gem::Requirement
34
33
  requirements:
35
- - - ! '>='
34
+ - - ">="
36
35
  - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
36
+ version: !binary |-
37
+ MA==
41
38
  none: false
39
+ requirement: !ruby/object:Gem::Requirement
42
40
  requirements:
43
- - - ! '>='
41
+ - - ">="
44
42
  - !ruby/object:Gem::Version
45
- version: '0'
43
+ version: !binary |-
44
+ MA==
45
+ none: false
46
+ prerelease: false
47
+ type: :development
46
48
  - !ruby/object:Gem::Dependency
47
49
  name: rspec
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
+ version_requirements: !ruby/object:Gem::Requirement
50
51
  requirements:
51
- - - ~>
52
+ - - "~>"
52
53
  - !ruby/object:Gem::Version
53
54
  version: '2.5'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
55
  none: false
56
+ requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - ~>
58
+ - - "~>"
60
59
  - !ruby/object:Gem::Version
61
60
  version: '2.5'
61
+ none: false
62
+ prerelease: false
63
+ type: :development
62
64
  - !ruby/object:Gem::Dependency
63
65
  name: sinatra
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
+ version_requirements: !ruby/object:Gem::Requirement
66
67
  requirements:
67
- - - ! '>='
68
+ - - ">="
68
69
  - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
70
+ version: !binary |-
71
+ MA==
73
72
  none: false
73
+ requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ! '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: !binary |-
78
+ MA==
79
+ none: false
80
+ prerelease: false
81
+ type: :development
78
82
  - !ruby/object:Gem::Dependency
79
83
  name: slim
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
84
+ version_requirements: !ruby/object:Gem::Requirement
82
85
  requirements:
83
- - - ! '>='
86
+ - - ">="
84
87
  - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
88
+ version: !binary |-
89
+ MA==
89
90
  none: false
91
+ requirement: !ruby/object:Gem::Requirement
90
92
  requirements:
91
- - - ! '>='
93
+ - - ">="
92
94
  - !ruby/object:Gem::Version
93
- version: '0'
95
+ version: !binary |-
96
+ MA==
97
+ none: false
98
+ prerelease: false
99
+ type: :development
94
100
  - !ruby/object:Gem::Dependency
95
101
  name: rack-test
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
102
+ version_requirements: !ruby/object:Gem::Requirement
98
103
  requirements:
99
- - - ~>
104
+ - - "~>"
100
105
  - !ruby/object:Gem::Version
101
106
  version: 0.5.4
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
107
  none: false
108
+ requirement: !ruby/object:Gem::Requirement
106
109
  requirements:
107
- - - ~>
110
+ - - "~>"
108
111
  - !ruby/object:Gem::Version
109
112
  version: 0.5.4
110
- description: A sidekiq plugin for specifying the queues a worker pulls from with wildcards,
111
- negations, or dynamic look up from redis
113
+ none: false
114
+ prerelease: false
115
+ type: :development
116
+ description: A sidekiq plugin for specifying the queues a worker pulls from with wildcards, negations, or dynamic look up from redis
112
117
  email:
113
118
  - matt@conwaysplace.com
114
119
  executables: []
115
120
  extensions: []
116
121
  extra_rdoc_files: []
117
122
  files:
118
- - .gitignore
119
- - .travis.yml
123
+ - ".gitignore"
124
+ - ".rvmrc"
125
+ - ".travis.yml"
120
126
  - CHANGELOG
121
127
  - Gemfile
122
128
  - LICENSE
@@ -138,32 +144,33 @@ files:
138
144
  - spec/spec_helper.rb
139
145
  homepage: ''
140
146
  licenses: []
141
- post_install_message:
147
+ post_install_message:
142
148
  rdoc_options: []
143
149
  require_paths:
144
150
  - lib
145
151
  required_ruby_version: !ruby/object:Gem::Requirement
146
- none: false
147
152
  requirements:
148
- - - ! '>='
153
+ - - ">="
149
154
  - !ruby/object:Gem::Version
150
- version: '0'
151
- required_rubygems_version: !ruby/object:Gem::Requirement
155
+ version: !binary |-
156
+ MA==
152
157
  none: false
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
159
  requirements:
154
- - - ! '>='
160
+ - - ">="
155
161
  - !ruby/object:Gem::Version
156
- version: '0'
162
+ version: !binary |-
163
+ MA==
164
+ none: false
157
165
  requirements: []
158
166
  rubyforge_project: sidekiq-dynamic-queues
159
- rubygems_version: 1.8.25
160
- signing_key:
167
+ rubygems_version: 1.8.24
168
+ signing_key:
161
169
  specification_version: 3
162
- summary: A sidekiq plugin for specifying the queues a worker pulls from with wildcards,
163
- negations, or dynamic look up from redis
170
+ summary: A sidekiq plugin for specifying the queues a worker pulls from with wildcards, negations, or dynamic look up from redis
164
171
  test_files:
165
172
  - spec/queues_spec.rb
166
173
  - spec/redis-test.conf
167
174
  - spec/server_spec.rb
168
175
  - spec/spec_helper.rb
169
- has_rdoc:
176
+ has_rdoc: