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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49ca8f7f8ee4321b4dddbea8fa4539b25d8655f7
4
- data.tar.gz: 6cb7174e7cd4f53820a37ec9c04fc2c1357e1317
3
+ metadata.gz: de0e824c76676500fcae642c033b9c4093910b82
4
+ data.tar.gz: 521b5daf99f15c297ae7eb0e76ce467ac9650889
5
5
  SHA512:
6
- metadata.gz: c5cc0b5fd08e3e4520e76859d3cb98f51ee42dc47d6f219ee4cb42b6c7f2692ae37569203018d9baf9f7127728f722f261efaebb46b01c448d663ec67f8507a8
7
- data.tar.gz: 5d3662c0b9b2d3d87dcafd8c9009f6e40eaf2f375372ac64c5afd72e062770f2fa5457cf6afb2c9d77f97c35ff526cf58f5d3e3b95f9177790943119c3d40793
6
+ metadata.gz: 6e6813574c68da4a4431130cf262572bae91fca7f6b0b5cf7a795e25900da40661a600953917fd271e34bdaff0f757249fbd956a05397f3e01c9e2972976ef04
7
+ data.tar.gz: f2e92f4c296886fd06cf8a54b8462c54ee53a3be7b68f922711a337a12e2bc51ae37b6939ddc0232ae89e1c63bc674d45f0731dde3cfee78841808d4c4a2402b
data/lib/zq.rb CHANGED
@@ -15,6 +15,7 @@ require 'zq/composers/json'
15
15
  require 'zq/composers/redis'
16
16
  require 'zq/composers/io'
17
17
 
18
+ require 'zq/sources/mixins'
18
19
  require 'zq/sources/io'
19
20
  require 'zq/sources/redis'
20
21
 
@@ -103,10 +103,7 @@ module ZQ
103
103
  Kernel.sleep(interval)
104
104
  end
105
105
 
106
- def process_until_exhausted
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
@@ -1,6 +1,7 @@
1
1
  module ZQ
2
2
  module Sources
3
3
  class IOSource
4
+ include NonTransactional
4
5
  def initialize file
5
6
  @file = file
6
7
  end
@@ -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
+
@@ -1,14 +1,69 @@
1
1
  module ZQ
2
2
  module Sources
3
- class RedisLPOP
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.lpop @listname
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
@@ -1,3 +1,3 @@
1
1
  module ZQ
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.2
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-04-27 00:00:00.000000000 Z
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/zimtw
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.8.6
61
+ version: 1.9.2
61
62
  required_rubygems_version: !ruby/object:Gem::Requirement
62
63
  requirements:
63
64
  - - '>='