redis_open3 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_open3.rb +8 -6
- data/lib/redis_open3/enum.rb +10 -1
- data/lib/redis_open3/error.rb +3 -0
- data/lib/redis_open3/version.rb +1 -1
- data/spec/lib/redis_open3/enum_spec.rb +21 -0
- data/spec/lib/redis_open3_spec.rb +23 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 394d841ea55842e0efe813e5e2734f27d852cd20
|
4
|
+
data.tar.gz: 812e91f841ba305844b47091dbea610200f4c905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d56133410c8fc67db16af3cc23918dccab6ef0f352e9b7c5c1183247e496e3f86a05b2e0649a0ff336c0ed677554085e2ec07e02d11100060e93bb3bdaa56f7
|
7
|
+
data.tar.gz: 42894d54ed96ebe807e13323f0cad450a9362db8f6c779432fcd7f16ae6eebee01a25531cba0432f93bc7a1e3659695c7741c64a023f03483971f4c8bfe5ee89
|
data/lib/redis_open3.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require '
|
1
|
+
require 'redis_open3/version'
|
2
|
+
require 'redis_open3/enum'
|
3
3
|
|
4
4
|
class RedisOpen3
|
5
|
-
class Error < StandardError; end
|
6
|
-
|
7
5
|
IN_KEY = 'redis_open3_in'
|
8
6
|
OUT_KEY = 'redis_open3_out'
|
9
7
|
ERR_KEY = 'redis_open3_err'
|
@@ -17,11 +15,14 @@ class RedisOpen3
|
|
17
15
|
with_enums(generated_uuids) do |redis_in, redis_out, redis_err, uuids|
|
18
16
|
begin
|
19
17
|
yield redis_in, redis_out, redis_err, uuids
|
18
|
+
rescue Exception => e
|
19
|
+
redis_in.fail
|
20
|
+
raise e
|
20
21
|
ensure
|
21
|
-
redis_in.close
|
22
22
|
redis_out.delete
|
23
23
|
redis_err.delete
|
24
24
|
end
|
25
|
+
redis_in.close
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
@@ -30,13 +31,14 @@ class RedisOpen3
|
|
30
31
|
begin
|
31
32
|
yield redis_in, redis_out, redis_err
|
32
33
|
rescue Exception => e
|
34
|
+
redis_out.fail
|
33
35
|
([e.inspect] + e.backtrace).each { |row| redis_err << row }
|
34
36
|
raise e
|
35
37
|
ensure
|
36
38
|
redis_in.delete
|
37
|
-
redis_out.close
|
38
39
|
redis_err.close
|
39
40
|
end
|
41
|
+
redis_out.close
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
data/lib/redis_open3/enum.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'redis'
|
2
|
-
require 'redis_open3'
|
2
|
+
require 'redis_open3/error'
|
3
3
|
|
4
4
|
class RedisOpen3
|
5
5
|
class Enum
|
6
6
|
class TimeoutError < RedisOpen3::Error; end
|
7
|
+
class Error < RedisOpen3::Error; end
|
7
8
|
|
8
9
|
include Enumerable
|
9
10
|
attr_reader :list_name
|
@@ -12,6 +13,9 @@ class RedisOpen3
|
|
12
13
|
EOF = '90829c12-3ac3-4af9-aeb4-8b63d1cc1d23'
|
13
14
|
EOF_REGX = /\A#{EOF}\z/
|
14
15
|
|
16
|
+
ERR = '7ce43256-a6ed-4890-9352-956ab8816dbd'
|
17
|
+
ERR_REGX = /\A#{ERR}\z/
|
18
|
+
|
15
19
|
def initialize(list_name, opts={})
|
16
20
|
@list_name = list_name
|
17
21
|
@timeout = opts[:timeout]
|
@@ -29,6 +33,7 @@ class RedisOpen3
|
|
29
33
|
def each(&block)
|
30
34
|
Enumerator.new do |y|
|
31
35
|
until (line = pop.chomp) =~ EOF_REGX
|
36
|
+
raise Error, "Received error signal." if line =~ ERR_REGX
|
32
37
|
y << line
|
33
38
|
end
|
34
39
|
end.each(&block)
|
@@ -38,6 +43,10 @@ class RedisOpen3
|
|
38
43
|
@redis.del(list_name)
|
39
44
|
end
|
40
45
|
|
46
|
+
def fail
|
47
|
+
push(ERR)
|
48
|
+
end
|
49
|
+
|
41
50
|
private
|
42
51
|
|
43
52
|
def push(string)
|
data/lib/redis_open3/version.rb
CHANGED
@@ -63,9 +63,30 @@ describe RedisOpen3::Enum do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
describe '#fail' do
|
67
|
+
let(:err) { RedisOpen3::Enum::ERR }
|
68
|
+
|
69
|
+
it 'adds the ERR uuid to the redis list' do
|
70
|
+
RedisConn.with do |redis|
|
71
|
+
expect {
|
72
|
+
enum.fail
|
73
|
+
}.to change {
|
74
|
+
redis.lpop(list_name)
|
75
|
+
}.from(nil).to(err)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
66
80
|
context 'timeout' do
|
67
81
|
it 'raises a timeout error if the timeout expires' do
|
68
82
|
expect { enum.each.to_a }.to raise_error(RedisOpen3::Enum::TimeoutError)
|
69
83
|
end
|
70
84
|
end
|
85
|
+
|
86
|
+
context 'when an error signal is sent' do
|
87
|
+
it 'raises a command failed error' do
|
88
|
+
RedisConn.with { |redis| redis.lpush(enum.list_name, RedisOpen3::Enum::ERR)}
|
89
|
+
expect { enum.each.to_a }.to raise_error(RedisOpen3::Enum::Error)
|
90
|
+
end
|
91
|
+
end
|
71
92
|
end
|
@@ -5,7 +5,7 @@ describe RedisOpen3 do
|
|
5
5
|
let(:conns) { RedisConn.method(:with) }
|
6
6
|
|
7
7
|
describe '#popen3' do
|
8
|
-
it 'yields 3 redis enum objects and
|
8
|
+
it 'yields 3 redis enum objects and a hash with their list uuids' do
|
9
9
|
ropen.open3 do |r_in, r_out, r_err, uuids|
|
10
10
|
expect(uuids[RedisOpen3::IN_KEY]).to eq r_in.list_name
|
11
11
|
expect(uuids[RedisOpen3::OUT_KEY]).to eq r_out.list_name
|
@@ -35,6 +35,17 @@ describe RedisOpen3 do
|
|
35
35
|
expect(redis.exists(err_name)).to eq false
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
context 'an exception is raised' do
|
40
|
+
it 'sends fail to redis_in' do
|
41
|
+
expect {
|
42
|
+
ropen.open3 do |redis_in|
|
43
|
+
expect(redis_in).to receive(:fail)
|
44
|
+
raise 'fail'
|
45
|
+
end
|
46
|
+
}.to raise_error RuntimeError, 'fail'
|
47
|
+
end
|
48
|
+
end
|
38
49
|
end
|
39
50
|
|
40
51
|
describe '#process3' do
|
@@ -69,5 +80,16 @@ describe RedisOpen3 do
|
|
69
80
|
expect(redis.exists(uuids[RedisOpen3::IN_KEY])).to eq false
|
70
81
|
end
|
71
82
|
end
|
83
|
+
|
84
|
+
context 'an exception is raised' do
|
85
|
+
it 'sends fail to redis_out' do
|
86
|
+
expect {
|
87
|
+
ropen.process3(uuids) do |_, redis_out|
|
88
|
+
expect(redis_out).to receive(:fail)
|
89
|
+
raise 'fail'
|
90
|
+
end
|
91
|
+
}.to raise_error RuntimeError, 'fail'
|
92
|
+
end
|
93
|
+
end
|
72
94
|
end
|
73
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_open3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Hartland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/redis_open3.rb
|
83
83
|
- lib/redis_open3/enum.rb
|
84
|
+
- lib/redis_open3/error.rb
|
84
85
|
- lib/redis_open3/version.rb
|
85
86
|
- redis_open3.gemspec
|
86
87
|
- spec/lib/redis_open3/enum_spec.rb
|