freddy 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/freddy.gemspec +1 -1
- data/lib/freddy.rb +6 -0
- data/lib/freddy/request_manager.rb +2 -1
- data/lib/freddy/sync_response_container.rb +4 -2
- data/spec/freddy/freddy_spec.rb +7 -7
- data/spec/integration/concurrency_spec.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc5a587ccd4505868a43c8444abdbb376d30e124
|
4
|
+
data.tar.gz: f4f09ae1d1f046689e71245b9170cf9154fa0946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9e6c129c97c63e92abdb3449f127fdb3c64dcf6b73a385b3bd3acd57682f8d3ceb30850e3a38a3431cc7bd61408f2177db9f861547beed33ff58e9babc7b4ba
|
7
|
+
data.tar.gz: bdcc1cbb44b821cda0494177c326eab270f254e2c0cb8988bd620f3dbb221967788c2ec58bbe23c87f416fd2f85d4d9724e80d242868fb0c47662cce64a71ec9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -49,13 +49,15 @@ response = freddy.deliver_with_response(destination, message, timeout: 4, delete
|
|
49
49
|
```
|
50
50
|
|
51
51
|
#### Errors
|
52
|
-
`deliver_with_response` raises an error if an error is returned. This can be handled by rescuing from `Freddy::
|
52
|
+
`deliver_with_response` raises an error if an error is returned. This can be handled by rescuing from `Freddy::InvalidRequestError` and `Freddy::TimeoutError` as:
|
53
53
|
```ruby
|
54
54
|
begin
|
55
55
|
response = freddy.deliver_with_response 'Q', {}
|
56
56
|
# ...
|
57
|
-
rescue Freddy::
|
58
|
-
e.response # => { error: '
|
57
|
+
rescue Freddy::InvalidRequestError => e
|
58
|
+
e.response # => { error: 'InvalidRequestError', message: 'Some error message' }
|
59
|
+
rescue Freddy::TimeoutError => e
|
60
|
+
e.response # => { error: 'RequestTimeout', message: 'Timed out waiting for response' }
|
59
61
|
```
|
60
62
|
|
61
63
|
## Responding to messages
|
data/freddy.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "freddy"
|
7
|
-
spec.version = '0.3.
|
7
|
+
spec.version = '0.3.4'
|
8
8
|
spec.authors = ["Urmas Talimaa"]
|
9
9
|
spec.email = ["urmas.talimaa@gmail.com"]
|
10
10
|
spec.description = %q{Messaging API}
|
data/lib/freddy.rb
CHANGED
@@ -35,7 +35,8 @@ class Freddy
|
|
35
35
|
message = "Request #{correlation_id} timed out waiting response from #{request[:destination]} with timeout #{request[:timeout]}"
|
36
36
|
@logger.warn message
|
37
37
|
Freddy.notify 'RequestTimeout', message, request: correlation_id, destination: request[:destination], timeout: request[:timeout]
|
38
|
-
|
38
|
+
|
39
|
+
request[:callback].call({error: 'RequestTimeout', message: 'Timed out waiting for response'}, nil)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
@@ -12,8 +12,10 @@ class Freddy
|
|
12
12
|
sleep 0.001 until filled?
|
13
13
|
end
|
14
14
|
|
15
|
-
if
|
16
|
-
raise
|
15
|
+
if @response[:error] == 'RequestTimeout'
|
16
|
+
raise TimeoutError.new(@response)
|
17
|
+
elsif !@delivery || @delivery.properties[:type] == 'error'
|
18
|
+
raise InvalidRequestError.new(@response)
|
17
19
|
else
|
18
20
|
@response
|
19
21
|
end
|
data/spec/freddy/freddy_spec.rb
CHANGED
@@ -60,7 +60,7 @@ describe Freddy do
|
|
60
60
|
|
61
61
|
expect {
|
62
62
|
freddy.deliver_with_response(destination, payload)
|
63
|
-
}.to raise_error(Freddy::
|
63
|
+
}.to raise_error(Freddy::InvalidRequestError) {|error|
|
64
64
|
expect(error.response).to eq(error: 'not today')
|
65
65
|
}
|
66
66
|
end
|
@@ -88,7 +88,7 @@ describe Freddy do
|
|
88
88
|
|
89
89
|
expect {
|
90
90
|
freddy.deliver_with_response(destination2, payload)
|
91
|
-
}.to raise_error(Freddy::
|
91
|
+
}.to raise_error(Freddy::InvalidRequestError)
|
92
92
|
end
|
93
93
|
|
94
94
|
context 'when queue does not exist' do
|
@@ -97,7 +97,7 @@ describe Freddy do
|
|
97
97
|
Timeout::timeout(0.5) do
|
98
98
|
expect {
|
99
99
|
freddy.deliver_with_response(destination, {a: 'b'}, timeout: 3)
|
100
|
-
}.to raise_error(Freddy::
|
100
|
+
}.to raise_error(Freddy::InvalidRequestError) {|error|
|
101
101
|
expect(error.response).to eq(error: 'Specified queue does not exist')
|
102
102
|
}
|
103
103
|
end
|
@@ -113,8 +113,8 @@ describe Freddy do
|
|
113
113
|
|
114
114
|
expect {
|
115
115
|
freddy.deliver_with_response(destination, {a: 'b'}, timeout: 0.1)
|
116
|
-
}.to raise_error(Freddy::
|
117
|
-
expect(error.response).to eq(error: 'Timed out waiting for response')
|
116
|
+
}.to raise_error(Freddy::TimeoutError) {|error|
|
117
|
+
expect(error.response).to eq(error: 'RequestTimeout', message: 'Timed out waiting for response')
|
118
118
|
}
|
119
119
|
end
|
120
120
|
|
@@ -126,7 +126,7 @@ describe Freddy do
|
|
126
126
|
|
127
127
|
expect {
|
128
128
|
freddy.deliver_with_response(destination, {}, timeout: 0.1)
|
129
|
-
}.to raise_error(Freddy::
|
129
|
+
}.to raise_error(Freddy::TimeoutError)
|
130
130
|
default_sleep # to ensure everything is properly cleaned
|
131
131
|
|
132
132
|
processed_after_timeout = false
|
@@ -145,7 +145,7 @@ describe Freddy do
|
|
145
145
|
|
146
146
|
expect {
|
147
147
|
freddy.deliver_with_response(destination, {}, timeout: 0.1, delete_on_timeout: false)
|
148
|
-
}.to raise_error(Freddy::
|
148
|
+
}.to raise_error(Freddy::TimeoutError)
|
149
149
|
default_sleep # to ensure everything is properly cleaned
|
150
150
|
|
151
151
|
processed_after_timeout = false
|
@@ -8,7 +8,7 @@ describe 'Concurrency' do
|
|
8
8
|
begin
|
9
9
|
result = freddy.deliver_with_response 'Concurrency2', msg: 'noop'
|
10
10
|
msg_handler.success(result)
|
11
|
-
rescue Freddy::
|
11
|
+
rescue Freddy::InvalidRequestError => e
|
12
12
|
msg_handler.error(e.response)
|
13
13
|
end
|
14
14
|
end
|
@@ -17,7 +17,7 @@ describe 'Concurrency' do
|
|
17
17
|
begin
|
18
18
|
result = freddy.deliver_with_response 'Concurrency3', msg: 'noop'
|
19
19
|
msg_handler.success(result)
|
20
|
-
rescue Freddy::
|
20
|
+
rescue Freddy::InvalidRequestError => e
|
21
21
|
msg_handler.error(e.response)
|
22
22
|
end
|
23
23
|
end
|
@@ -29,7 +29,7 @@ describe 'Concurrency' do
|
|
29
29
|
result =
|
30
30
|
begin
|
31
31
|
freddy.deliver_with_response 'Concurrency1', msg: 'noop'
|
32
|
-
rescue Freddy::
|
32
|
+
rescue Freddy::InvalidRequestError => e
|
33
33
|
e.response
|
34
34
|
end
|
35
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freddy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Urmas Talimaa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.4.3
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: API for inter-application messaging supporting acknowledgements and request-response
|