zq 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zq.rb +1 -0
- data/lib/zq/orchestra.rb +18 -4
- data/lib/zq/sources/io.rb +1 -0
- data/lib/zq/sources/mixins.rb +25 -0
- data/lib/zq/sources/redis.rb +57 -2
- data/lib/zq/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de0e824c76676500fcae642c033b9c4093910b82
|
4
|
+
data.tar.gz: 521b5daf99f15c297ae7eb0e76ce467ac9650889
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e6813574c68da4a4431130cf262572bae91fca7f6b0b5cf7a795e25900da40661a600953917fd271e34bdaff0f757249fbd956a05397f3e01c9e2972976ef04
|
7
|
+
data.tar.gz: f2e92f4c296886fd06cf8a54b8462c54ee53a3be7b68f922711a337a12e2bc51ae37b6939ddc0232ae89e1c63bc674d45f0731dde3cfee78841808d4c4a2402b
|
data/lib/zq.rb
CHANGED
data/lib/zq/orchestra.rb
CHANGED
@@ -103,10 +103,7 @@ module ZQ
|
|
103
103
|
Kernel.sleep(interval)
|
104
104
|
end
|
105
105
|
|
106
|
-
def
|
107
|
-
loop do
|
108
|
-
item = @source.read_next
|
109
|
-
break if item.nil?
|
106
|
+
def compose(item)
|
110
107
|
composite = nil
|
111
108
|
begin
|
112
109
|
@composers.each do |c|
|
@@ -115,6 +112,23 @@ module ZQ
|
|
115
112
|
rescue
|
116
113
|
raise unless self.class.ignore_errors?
|
117
114
|
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def process_until_exhausted
|
118
|
+
this = self
|
119
|
+
catch :exhausted do
|
120
|
+
loop do
|
121
|
+
if @source.transactional?
|
122
|
+
@source.transaction do |item|
|
123
|
+
throw :exhausted if item.nil?
|
124
|
+
this.compose(item)
|
125
|
+
end
|
126
|
+
else
|
127
|
+
item = @source.read_next
|
128
|
+
throw :exhausted if item.nil?
|
129
|
+
compose(item)
|
130
|
+
end
|
131
|
+
end
|
118
132
|
end
|
119
133
|
end
|
120
134
|
end
|
data/lib/zq/sources/io.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module ZQ
|
2
|
+
module Sources
|
3
|
+
module NonTransactional
|
4
|
+
def transactional?
|
5
|
+
false
|
6
|
+
end
|
7
|
+
end
|
8
|
+
module TransactionalMixin
|
9
|
+
def transactional?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def transaction(&block)
|
14
|
+
item = self.read_next
|
15
|
+
begin
|
16
|
+
self.commit(item) if yield(item)
|
17
|
+
rescue => error
|
18
|
+
self.rollback(item)
|
19
|
+
throw :exhausted # or raise ?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/zq/sources/redis.rb
CHANGED
@@ -1,14 +1,69 @@
|
|
1
1
|
module ZQ
|
2
2
|
module Sources
|
3
|
-
|
3
|
+
|
4
|
+
class RedisListOP
|
5
|
+
include NonTransactional
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :client_method
|
9
|
+
end
|
10
|
+
|
4
11
|
def initialize(client, listname)
|
5
12
|
@client = client
|
6
13
|
@listname = listname
|
7
14
|
end
|
8
15
|
|
9
16
|
def read_next
|
10
|
-
@client.
|
17
|
+
@client.send(self.class.client_method, *args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def args
|
21
|
+
@listname
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.method(client_method)
|
25
|
+
self.client_method = client_method
|
11
26
|
end
|
12
27
|
end
|
28
|
+
|
29
|
+
class RedisRPOPLPUSH < RedisListOP
|
30
|
+
include TransactionalMixin
|
31
|
+
method :rpoplpush
|
32
|
+
|
33
|
+
def initialize(client, listname, progress_listname=nil)
|
34
|
+
@client = client
|
35
|
+
@listname = listname
|
36
|
+
@progress_listname = progress_listname
|
37
|
+
end
|
38
|
+
|
39
|
+
def args
|
40
|
+
[@listname, progress_listname]
|
41
|
+
end
|
42
|
+
|
43
|
+
def progress_listname
|
44
|
+
@progress_listname || @listname + '_progress'
|
45
|
+
end
|
46
|
+
|
47
|
+
def rollback(item)
|
48
|
+
@client.rpush(@listname, item)
|
49
|
+
end
|
50
|
+
|
51
|
+
def commit(item)
|
52
|
+
@client.lrem(progress_listname, 0, item)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class RedisTransactionalQueue < RedisRPOPLPUSH
|
57
|
+
method :rpoplpush
|
58
|
+
end
|
59
|
+
|
60
|
+
class RedisLPOP < RedisListOP
|
61
|
+
method :lpop
|
62
|
+
end
|
63
|
+
|
64
|
+
class RedisRPOP < RedisListOP
|
65
|
+
method :rpop
|
66
|
+
end
|
67
|
+
|
13
68
|
end
|
14
69
|
end
|
data/lib/zq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kai Richard Koenig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -40,12 +40,13 @@ files:
|
|
40
40
|
- lib/zq/orchestra.rb
|
41
41
|
- lib/zq/orchestras/echo.rb
|
42
42
|
- lib/zq/sources/io.rb
|
43
|
+
- lib/zq/sources/mixins.rb
|
43
44
|
- lib/zq/sources/redis.rb
|
44
45
|
- lib/zq/utils.rb
|
45
46
|
- lib/zq/version.rb
|
46
47
|
- lib/zq.rb
|
47
48
|
- bin/zq
|
48
|
-
homepage: https://github.com/kairichard/
|
49
|
+
homepage: https://github.com/kairichard/zq
|
49
50
|
licenses:
|
50
51
|
- MIT
|
51
52
|
metadata: {}
|
@@ -57,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
58
|
requirements:
|
58
59
|
- - '>='
|
59
60
|
- !ruby/object:Gem::Version
|
60
|
-
version: 1.
|
61
|
+
version: 1.9.2
|
61
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
63
|
requirements:
|
63
64
|
- - '>='
|