sub_zero 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c3d06f3806bd38f972069cccc381a5e14a10552
4
- data.tar.gz: 201442b45283cc753950167905a088a450ec613a
3
+ metadata.gz: 1d2f91d35235df49176ba39a8f3cd6bf5cbca454
4
+ data.tar.gz: ada80f112ceff71a231d9bf2b05c05ce30cb66a2
5
5
  SHA512:
6
- metadata.gz: 59833793e76d2543ad4ed8948f852b7a8b13b0db67e44352cf55c4df36044b16669f84cd8a6e5df9e8134a7c20f36a245bbe760b7fd3c5a30696ebe61b56dacf
7
- data.tar.gz: 2aee09d0ea9f147d2acf510203f0b71d7619876b8dbe5750d32f6153f1710ce0e6aad0cdfdd1d96013a96643928c36a11becfc4c5f7b02e61efc2ce1eed31b3c
6
+ metadata.gz: 496a8f67eb47c3105724e05cab034f5efd519c120f7d6807de1173b2015c57692a622d6f25204fa11446be2a5fb84276d9c58dbe2727929108d79f85bcc11ac1
7
+ data.tar.gz: 5d0dc86764da65b7eacff51daa6431fd091a7a2055864bc8c84377bf8f15488df15ebc569c382ea2505e1cdfb6103ccc33929fbfb43ff962b329d9d64bf25174
@@ -12,15 +12,21 @@ module SubZero
12
12
  def zeromq_fetch verb, payload = {}, options = {}
13
13
  result = []
14
14
 
15
- zeromq_context do |context|
16
- zeromq_socket context do |socket|
17
- rid = SecureRandom.uuid
18
- zeromq_send socket, "REQ:#{sid}", rid, verb, payload.to_msgpack, options.to_msgpack
19
- result = zeromq_result(socket, rid, verb)
15
+ timeout = options.fetch(:timeout, 1000) / 1000.0
16
+
17
+ Timeout.timeout timeout do
18
+ zeromq_context do |context|
19
+ zeromq_socket context do |socket|
20
+ rid = SecureRandom.uuid
21
+ zeromq_send socket, "REQ:#{sid}", rid, verb, payload.to_msgpack, options.to_msgpack
22
+ result = zeromq_result(socket, rid, verb)
23
+ end
20
24
  end
21
25
  end
22
26
 
23
27
  result
28
+ rescue Timeout::Error
29
+ raise SubZero::Client::Error.new(code: 'timeout', message: "call timeout: #{timeout}s")
24
30
  end
25
31
 
26
32
  def zeromq_context
@@ -62,7 +68,7 @@ module SubZero
62
68
  zeromq_validate_result! rid, verb, result
63
69
 
64
70
  routing_info = MessagePack.unpack(result.pop)
65
- payload = MessagePack.unpack(result.pop)
71
+ payload = MessagePack.unpack(result.pop)
66
72
  rep_verb = result.pop
67
73
  status = rep_verb.end_with?('NOK') ? :error : :ok
68
74
 
@@ -1,4 +1,5 @@
1
1
  require 'active_support/string_inquirer'
2
+ require 'active_support/hash_with_indifferent_access'
2
3
 
3
4
  module SubZero
4
5
  class Client
@@ -17,7 +18,7 @@ module SubZero
17
18
  def call verb, payload = {}, options = {}
18
19
  sz_verb = verb.to_s.upcase.gsub('_', '/')
19
20
  status, result = zeromq_fetch(sz_verb, payload, options)
20
- result = handle_result(status, result)
21
+ result = handle_result(status, result).with_indifferent_access
21
22
  block_given? ? yield(result) : result
22
23
  end
23
24
 
@@ -1,3 +1,3 @@
1
1
  module SubZero
2
- VERSION = "0.0.3"
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/sub_zero.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'securerandom'
3
+ require 'timeout'
3
4
 
4
5
  require 'thor'
5
6
  require 'thor/group'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sub_zero
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
  - Victor Rodrigues
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  version: '0'
177
177
  requirements: []
178
178
  rubyforge_project:
179
- rubygems_version: 2.0.7
179
+ rubygems_version: 2.0.3
180
180
  signing_key:
181
181
  specification_version: 4
182
182
  summary: ZeroMQ GREAT SOA solution