redis_queue 0.3.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_queue.rb +16 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 070b9946924ad3d989f088bbf2d4e246bcdeb46c
|
4
|
+
data.tar.gz: e271e4dc1e7ee9423b60d7f76309833d6cf3144d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5265930448447d46b649203c00020e7ed21136c18e36ac6351f58fadc8b350ba03e8b5a1eeee92f53bb19f21cc669ecd30a704895a90b610df796a7396efdb08
|
7
|
+
data.tar.gz: d4821d42bcbc251170f4071f48ccbc6324576ce5fb16d592d27f792e7ac53ce3a03a28d6cee63fb5b629c9b4eda66b2317093ff8d4930635d0969a524b019c02
|
data/lib/redis_queue.rb
CHANGED
@@ -2,6 +2,17 @@ require_relative 'redis_connection'
|
|
2
2
|
|
3
3
|
class RedisQueue
|
4
4
|
SCRIPTS = {
|
5
|
+
push: """
|
6
|
+
if ARGV[3] == 'true' then
|
7
|
+
local insert = redis.call('linsert', ARGV[1], 'before', '', ARGV[2])
|
8
|
+
if insert == -1 or insert == 0 then
|
9
|
+
redis.call('lpush', ARGV[1], '')
|
10
|
+
redis.call('lpush', ARGV[1], ARGV[2])
|
11
|
+
end
|
12
|
+
else
|
13
|
+
redis.call('rpush', ARGV[1], ARGV[2])
|
14
|
+
end
|
15
|
+
""",
|
5
16
|
fail: """
|
6
17
|
redis.call('sadd', ARGV[1]..'_failed', ARGV[2])
|
7
18
|
redis.call('srem', ARGV[1]..'_in_use', ARGV[2])
|
@@ -29,13 +40,15 @@ class RedisQueue
|
|
29
40
|
end
|
30
41
|
|
31
42
|
def pop
|
32
|
-
|
43
|
+
begin
|
44
|
+
task = @redis_blocking.run { |redis| redis.blpop(@id) }.last
|
45
|
+
end while task == ''
|
33
46
|
@redis.run { |redis| redis.sadd "#{@id}_in_use", task }
|
34
47
|
task
|
35
48
|
end
|
36
49
|
|
37
|
-
def push task
|
38
|
-
|
50
|
+
def push task, priority=false
|
51
|
+
script :push, @id, task, priority
|
39
52
|
end
|
40
53
|
|
41
54
|
def fail task
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Ignacio Fernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|