lagomorph 0.0.3 → 0.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/lagomorph.rb +1 -0
- data/lib/lagomorph/exceptions.rb +4 -0
- data/lib/lagomorph/rpc_call.rb +1 -1
- data/lib/lagomorph/subscriber.rb +9 -3
- data/lib/lagomorph/version.rb +1 -1
- data/spec/lagomorph_spec.rb +14 -2
- 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: f43d382ccc8fe66d01a384b667f7e0f62262bdcf
|
4
|
+
data.tar.gz: 977b4050ddff3f9ee3e45421e568d72a01b8f795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c19998e240ab84e68a26d698282446c2ab42d5e991d24c629b695619502cf3750f04b3e9d450ce4b9b8b15805ab87e1b3b3b858be22d8eda51b5c6dfc7df8ca9
|
7
|
+
data.tar.gz: 7af061a4eef4927797ef2b07d7652a45abcff4c2d0751ac106f5e7d539dd7efca85f616164f9d63ff7ed4ef8429a594c45907b52105dac37ca7a69b3c14a9799
|
data/lib/lagomorph.rb
CHANGED
data/lib/lagomorph/rpc_call.rb
CHANGED
@@ -24,7 +24,7 @@ module Lagomorph
|
|
24
24
|
publish_rpc_call(payload, correlation_id)
|
25
25
|
response = block_till_receive_response(correlation_id)
|
26
26
|
|
27
|
-
response['result'] || (
|
27
|
+
response['result'] || fail(RpcError, response.fetch('error'))
|
28
28
|
end
|
29
29
|
|
30
30
|
def close_channel
|
data/lib/lagomorph/subscriber.rb
CHANGED
@@ -9,8 +9,7 @@ module Lagomorph
|
|
9
9
|
|
10
10
|
def subscribe(queue, channel)
|
11
11
|
queue.subscribe(manual_ack: true, block: false) do |metadata, payload|
|
12
|
-
|
13
|
-
response = build_response(result)
|
12
|
+
response = process_request(payload)
|
14
13
|
channel.ack(metadata.delivery_tag)
|
15
14
|
publish_response(channel, metadata, response)
|
16
15
|
end
|
@@ -21,7 +20,10 @@ module Lagomorph
|
|
21
20
|
|
22
21
|
def process_request(request)
|
23
22
|
method, params = parse_request(request)
|
24
|
-
@worker_class.new(method, *params).work
|
23
|
+
result = @worker_class.new(method, *params).work
|
24
|
+
build_response(result)
|
25
|
+
rescue => e
|
26
|
+
build_error(e.message)
|
25
27
|
end
|
26
28
|
|
27
29
|
def publish_response(channel, metadata, payload)
|
@@ -38,5 +40,9 @@ module Lagomorph
|
|
38
40
|
JsonParser.new.build_response(result)
|
39
41
|
end
|
40
42
|
|
43
|
+
def build_error(error)
|
44
|
+
JsonParser.new.build_error(error)
|
45
|
+
end
|
46
|
+
|
41
47
|
end
|
42
48
|
end
|
data/lib/lagomorph/version.rb
CHANGED
data/spec/lagomorph_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require 'lagomorph/session'
|
|
4
4
|
require 'lagomorph/supervisor'
|
5
5
|
require 'lagomorph/subscriber'
|
6
6
|
require 'lagomorph/rpc_call'
|
7
|
+
require 'lagomorph/exceptions'
|
7
8
|
|
8
9
|
describe 'a Lagomorph RPC process' do
|
9
10
|
|
@@ -21,6 +22,10 @@ describe 'a Lagomorph RPC process' do
|
|
21
22
|
def echo(request)
|
22
23
|
request
|
23
24
|
end
|
25
|
+
|
26
|
+
def generate_failure
|
27
|
+
fail 'Could not process request'
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
context 'when supervising a PongWorker on the ping queue' do
|
@@ -42,7 +47,7 @@ describe 'a Lagomorph RPC process' do
|
|
42
47
|
supervisor.route queue, PongWorker
|
43
48
|
end
|
44
49
|
|
45
|
-
context 'and we have an rpc call
|
50
|
+
context 'and we have an rpc call' do
|
46
51
|
let!(:rpc_call) { Lagomorph::RpcCall.new(session) }
|
47
52
|
|
48
53
|
context 'when a pong rpc call is made on the ping queue' do
|
@@ -54,6 +59,13 @@ describe 'a Lagomorph RPC process' do
|
|
54
59
|
let(:result) { rpc_call.dispatch(queue, 'echo', 'test') }
|
55
60
|
it { expect(result).to eq 'test' }
|
56
61
|
end
|
62
|
+
|
63
|
+
context 'when a generate_failure rpc call is made on the ping queue' do
|
64
|
+
let(:result) { rpc_call.dispatch(queue, 'generate_failure') }
|
65
|
+
it { expect { result }.to raise_error Lagomorph::RpcError,
|
66
|
+
'Could not process request' }
|
67
|
+
end
|
68
|
+
|
57
69
|
after { rpc_call.close_channel }
|
58
70
|
end
|
59
71
|
|
@@ -69,7 +81,7 @@ describe 'a Lagomorph RPC process' do
|
|
69
81
|
specify 'each thread will get the expected response' do
|
70
82
|
rpc_calls.map do |rpc_call|
|
71
83
|
Thread.new do
|
72
|
-
|
84
|
+
calls_per_thread.times.map { |call_index|
|
73
85
|
rpc_call.dispatch(queue, 'echo', call_index).tap { |result|
|
74
86
|
expect(result).to eq call_index
|
75
87
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lagomorph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Berardi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- Rakefile
|
145
145
|
- lagomorph.gemspec
|
146
146
|
- lib/lagomorph.rb
|
147
|
+
- lib/lagomorph/exceptions.rb
|
147
148
|
- lib/lagomorph/json_parser.rb
|
148
149
|
- lib/lagomorph/metadata_adapter.rb
|
149
150
|
- lib/lagomorph/queue_adapter.rb
|