resque-uniqueue 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/resque/uniqueue.rb +9 -3
- data/resque-uniqueue.gemspec +2 -2
- data/test/test_resque-uniqueue.rb +50 -17
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/resque/uniqueue.rb
CHANGED
@@ -11,14 +11,21 @@ module Resque
|
|
11
11
|
unique_queue?(queue) ? pop_unique(queue) : super
|
12
12
|
end
|
13
13
|
|
14
|
+
def remove_queue(queue)
|
15
|
+
super(queue)
|
16
|
+
redis.del("queue:#{queue}:uniqueue")
|
17
|
+
end
|
18
|
+
|
14
19
|
def push_unique(queue, item)
|
15
20
|
confirm_unique_queue_validity(queue)
|
16
21
|
watch_queue(queue)
|
22
|
+
queue = "queue:#{queue}"
|
17
23
|
redis.evalsha push_unique_eval_sha, [queue], [encode(item)]
|
18
24
|
end
|
19
25
|
|
20
26
|
def pop_unique(queue)
|
21
27
|
confirm_unique_queue_validity(queue)
|
28
|
+
queue = "queue:#{queue}"
|
22
29
|
decode redis.evalsha pop_unique_eval_sha, [queue]
|
23
30
|
end
|
24
31
|
|
@@ -28,10 +35,9 @@ module Resque
|
|
28
35
|
local set_name = list_name..':uniqueue'
|
29
36
|
local in_set = redis.call('sadd', set_name , ARGV[1])
|
30
37
|
if in_set == 1 then
|
31
|
-
redis.call('rpush', list_name, ARGV[1])
|
32
|
-
return in_set
|
38
|
+
return redis.call('rpush', list_name, ARGV[1])
|
33
39
|
end
|
34
|
-
return
|
40
|
+
return false
|
35
41
|
LUA
|
36
42
|
end
|
37
43
|
|
data/resque-uniqueue.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "resque-uniqueue"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Scruggs"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-06-02"
|
13
13
|
s.description = "Unique Resque queues using redis 1.6.0 scripting, sets and not much else"
|
14
14
|
s.email = "aaron@scrug.gs"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -143,6 +143,32 @@ class TestResqueUniqueue < Test::Unit::TestCase
|
|
143
143
|
|
144
144
|
end
|
145
145
|
|
146
|
+
context 'remove_queue' do
|
147
|
+
|
148
|
+
setup do
|
149
|
+
Resque.redis.flushall
|
150
|
+
Resque.unique_queues!
|
151
|
+
Resque.unique_queues= ['priority_10']
|
152
|
+
end
|
153
|
+
|
154
|
+
should 'work for normal queues' do
|
155
|
+
Resque.push('priority_20', {'name' => 'bob'})
|
156
|
+
assert Resque.redis.exists('queue:priority_20')
|
157
|
+
Resque.remove_queue('priority_20')
|
158
|
+
refute Resque.redis.exists 'queue:priority_20'
|
159
|
+
end
|
160
|
+
|
161
|
+
should 'work for unique queues' do
|
162
|
+
Resque.push('priority_10', {'name' => 'bob'})
|
163
|
+
assert Resque.redis.exists('queue:priority_10')
|
164
|
+
assert Resque.redis.exists('queue:priority_10:uniqueue')
|
165
|
+
Resque.remove_queue('priority_10')
|
166
|
+
refute Resque.redis.exists 'queue:priority_10'
|
167
|
+
refute Resque.redis.exists 'queue:priority_10:uniqueue'
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
146
172
|
context "unique queues" do
|
147
173
|
|
148
174
|
setup do
|
@@ -214,26 +240,36 @@ class TestResqueUniqueue < Test::Unit::TestCase
|
|
214
240
|
context 'push_unique' do
|
215
241
|
|
216
242
|
should 'create set & list if they do not exist' do
|
217
|
-
refute Resque.redis.exists 'priority_10'
|
218
|
-
refute Resque.redis.exists 'priority_10:uniqueue'
|
243
|
+
refute Resque.redis.exists 'queue:priority_10'
|
244
|
+
refute Resque.redis.exists 'queue:priority_10:uniqueue'
|
219
245
|
Resque.push('priority_10', {'name' => 'bob'})
|
220
|
-
assert Resque.redis.exists 'priority_10'
|
221
|
-
assert Resque.redis.exists 'priority_10:uniqueue'
|
246
|
+
assert Resque.redis.exists 'queue:priority_10'
|
247
|
+
assert Resque.redis.exists 'queue:priority_10:uniqueue'
|
222
248
|
end
|
223
249
|
|
224
250
|
should "add items to set and list if message unique" do
|
225
251
|
Resque.push('priority_10', {'name' => 'bob'})
|
226
|
-
assert_equal Resque.redis.llen('priority_10'), 1
|
227
|
-
assert_equal Resque.redis.scard('priority_10:uniqueue'), 1
|
252
|
+
assert_equal Resque.redis.llen('queue:priority_10'), 1
|
253
|
+
assert_equal Resque.redis.scard('queue:priority_10:uniqueue'), 1
|
228
254
|
end
|
229
255
|
|
230
256
|
should "not add item to queue if already on there" do
|
231
257
|
Resque.push('priority_10', {'name' => 'bob'})
|
232
|
-
assert_equal Resque.redis.llen('priority_10'), 1
|
233
|
-
assert_equal Resque.redis.scard('priority_10:uniqueue'), 1
|
258
|
+
assert_equal Resque.redis.llen('queue:priority_10'), 1
|
259
|
+
assert_equal Resque.redis.scard('queue:priority_10:uniqueue'), 1
|
234
260
|
Resque.push('priority_10', {'name' => 'bob'})
|
235
|
-
assert_equal Resque.redis.llen('priority_10'), 1
|
236
|
-
assert_equal Resque.redis.scard('priority_10:uniqueue'), 1
|
261
|
+
assert_equal Resque.redis.llen('queue:priority_10'), 1
|
262
|
+
assert_equal Resque.redis.scard('queue:priority_10:uniqueue'), 1
|
263
|
+
end
|
264
|
+
|
265
|
+
should "return queue length if unique job" do
|
266
|
+
assert_equal Resque.push('priority_10', {'name' => 'bob'}), 1
|
267
|
+
assert_equal Resque.push('priority_10', {'name' => 'robert'}), 2
|
268
|
+
end
|
269
|
+
|
270
|
+
should "return nil if duplicate job" do
|
271
|
+
assert_equal Resque.push('priority_10', {'name' => 'bob'}), 1
|
272
|
+
assert_nil Resque.push('priority_10', {'name' => 'bob'})
|
237
273
|
end
|
238
274
|
|
239
275
|
end
|
@@ -256,20 +292,17 @@ class TestResqueUniqueue < Test::Unit::TestCase
|
|
256
292
|
|
257
293
|
should 'remove job from list and set' do
|
258
294
|
Resque.push('priority_10', {'name' => 'bob'})
|
259
|
-
assert_equal Resque.redis.llen('priority_10'), 1
|
260
|
-
assert_equal Resque.redis.scard('priority_10:uniqueue'), 1
|
295
|
+
assert_equal Resque.redis.llen('queue:priority_10'), 1
|
296
|
+
assert_equal Resque.redis.scard('queue:priority_10:uniqueue'), 1
|
261
297
|
Resque.pop('priority_10')
|
262
|
-
assert_equal Resque.redis.llen('priority_10'), 0
|
263
|
-
assert_equal Resque.redis.scard('priority_10:uniqueue'), 0
|
298
|
+
assert_equal Resque.redis.llen('queue:priority_10'), 0
|
299
|
+
assert_equal Resque.redis.scard('queue:priority_10:uniqueue'), 0
|
264
300
|
end
|
265
301
|
|
266
302
|
end
|
267
303
|
|
268
304
|
end
|
269
305
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
306
|
end
|
274
307
|
|
275
308
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-uniqueue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
segments:
|
160
160
|
- 0
|
161
|
-
hash:
|
161
|
+
hash: 2315830065208087025
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
163
|
none: false
|
164
164
|
requirements:
|