lagomorph 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efb0c9a699dbf5706bbc949351fa2a83dc5839c3
4
- data.tar.gz: 658000870814c1e7dacbb99ef46384cd14ec9c00
3
+ metadata.gz: f43d382ccc8fe66d01a384b667f7e0f62262bdcf
4
+ data.tar.gz: 977b4050ddff3f9ee3e45421e568d72a01b8f795
5
5
  SHA512:
6
- metadata.gz: b1dd615c1ad6946efadb54609c95ba9f7d15eb0db86e2c503acbaecee7f754d4e14bc8626d4a2ab285be6ee24698b2a430438bec6c1def75998a8f889f302986
7
- data.tar.gz: c989d1041e28afff05bf0042e5e0f3890a670d43a5c1f9ea68a6a01e7a6ecc718d7a581cf40f9a0e86a11759eded68d6067063e746e1ee1f156556277828d32e
6
+ metadata.gz: c19998e240ab84e68a26d698282446c2ab42d5e991d24c629b695619502cf3750f04b3e9d450ce4b9b8b15805ab87e1b3b3b858be22d8eda51b5c6dfc7df8ca9
7
+ data.tar.gz: 7af061a4eef4927797ef2b07d7652a45abcff4c2d0751ac106f5e7d539dd7efca85f616164f9d63ff7ed4ef8429a594c45907b52105dac37ca7a69b3c14a9799
data/lib/lagomorph.rb CHANGED
@@ -31,3 +31,4 @@ require 'lagomorph/subscriber'
31
31
  require 'lagomorph/supervisor'
32
32
  require 'lagomorph/worker'
33
33
  require 'lagomorph/rpc_call'
34
+ require 'lagomorph/exceptions'
@@ -0,0 +1,4 @@
1
+ module Lagomorph
2
+ class Exception < ::Exception; end
3
+ class RpcError < Exception; end
4
+ end
@@ -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'] || (fail response.fetch('error'))
27
+ response['result'] || fail(RpcError, response.fetch('error'))
28
28
  end
29
29
 
30
30
  def close_channel
@@ -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
- result = process_request(payload)
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
@@ -1,3 +1,3 @@
1
1
  module Lagomorph
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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 manager thingy' do
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
- thread_results = calls_per_thread.times.map { |call_index|
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.3
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-11 00:00:00.000000000 Z
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