kimchi 0.0.6 → 0.0.7

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kimchi/version.rb +1 -1
  3. data/lib/wire.rb +52 -22
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8883424bb826544feaef6c94a6b55f11692b5d08
4
- data.tar.gz: f28ce0474a811d495876985354ffc03c489c6457
3
+ metadata.gz: 5654ac8ca0de9106fded06aca9f0191d7e470843
4
+ data.tar.gz: 865917d2156790f803f631aa93ce448f2134df2a
5
5
  SHA512:
6
- metadata.gz: 13a423da3a62ff956d1ed2e3eaa9d13db48d0af6070b0328abd4d3833e609a4c4b62d32f670e74be49f9226ce68948816c13919d5e5e00b577768533ee9382c2
7
- data.tar.gz: 382c61c84602b4e7591d44611bc5d4abbcd2aa8789a384b3ba269d8fe6ff0d8f946d8294582a55c3f0978a203cc4889525a19bf9ada6622a2abfc757a1d5cbce
6
+ metadata.gz: cec8f80cac3960fbc2be24be6ba42cca3f52c2aa99343c095b2bc4df867a2a0f7f4c25255f8d4cbbbaae56938d9fa6b79c57684d88791a42a1a0f866f578d9c9
7
+ data.tar.gz: b3cbbdd7d9b552ebb93b77a7f90c4ba474799a19799c2f21ae28daa2ab58d2d4fdd24d9707f6fe08a3d92658e125baa93cd6173d3da9c45380299e54f3085ec0
@@ -1,3 +1,3 @@
1
1
  module Kimchi
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/wire.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "rubygems"
2
+ require "fiber"
2
3
  require "uuid"
3
4
  require "bunny"
4
5
  require "net/http"
@@ -39,7 +40,7 @@ module Wire
39
40
  @function
40
41
  end
41
42
 
42
- def contexts=contexts
43
+ def contexts= contexts
43
44
  @contexts=contexts
44
45
  end
45
46
 
@@ -77,6 +78,27 @@ module Wire
77
78
  end
78
79
  end
79
80
 
81
+ class Message
82
+
83
+ @result = nil
84
+
85
+ def result
86
+ while @result == nil
87
+ sleep(1)
88
+ end
89
+
90
+ @result
91
+ end
92
+
93
+ def complete (result)
94
+ @result = result
95
+ end
96
+
97
+ def timeout ()
98
+ raise Timeout::Error.new
99
+ end
100
+ end
101
+
80
102
  class RabbitMQTransport
81
103
  def initialize (host, port)
82
104
  @connection = Bunny.new("amqp://#{host}:#{port}")
@@ -120,10 +142,12 @@ module Wire
120
142
  initialize_service(service_name).publish(invocation_signal.to_json, :routing_key => "#{version}.2", :headers => {"x-opt-callerId" => "#{@caller_id}"}, :content_type => "application/json", :message_id => "#{@uuid.generate}", :timestamp => Time.new.to_i)
121
143
  end
122
144
 
123
- def transmit(service_name, version, invocation_signal, callback, timeout_seconds)
145
+ def transmit(service_name, version, invocation_signal, timeout_seconds)
124
146
  message_id = "#{@uuid.generate}".freeze
125
- @message_hash[message_id] = MessageCallback.new(@message_hash, message_id, callback, timeout_seconds)
147
+ @message_hash[message_id] = MessageCallback.new(@message_hash, message_id, message = Message.new, timeout_seconds)
126
148
  initialize_service(service_name).publish(invocation_signal.to_json, :routing_key => "#{version}.2", :headers => {"x-opt-callerId" => "#{@caller_id}"}, :content_type => "application/json", :message_id => "#{message_id}", :timestamp => Time.new.to_i)
149
+
150
+ message
127
151
  end
128
152
  end
129
153
 
@@ -133,30 +157,36 @@ module Wire
133
157
  @port = port
134
158
  end
135
159
 
136
- def transmit (service_name, version, invocation_signal, callback, timeout_seconds)
137
- uri = URI("#{@host}:#{@port}/api/message")
138
- headers = {"Content-Type" => "application/json"}
139
- http = Net::HTTP.new(uri.host, uri.port)
140
- http.read_timeout = timeout_seconds
160
+ def transmit (service_name, version, invocation_signal, timeout_seconds)
161
+ message = Message.new
141
162
 
142
- invocation_signal.function.service = service_name
143
- invocation_signal.function.version = version
163
+ begin
164
+ uri = URI("#{@host}:#{@port}/api/message")
165
+ headers = {"Content-Type" => "application/json"}
166
+ http = Net::HTTP.new(uri.host, uri.port)
167
+ http.read_timeout = timeout_seconds
144
168
 
145
- context_hash = {}
146
- invocation_signal.contexts.each {|context| context.each{|key,value| context_hash[key] = value}}
147
- invocation_signal.contexts = context_hash
169
+ invocation_signal.function.service = service_name
170
+ invocation_signal.function.version = version
148
171
 
149
- res = http.post(uri.path, invocation_signal.to_json, headers)
172
+ context_hash = {}
173
+ invocation_signal.contexts.each { |context| context.each { |key, value| context_hash[key] = value } }
174
+ invocation_signal.contexts = context_hash
150
175
 
151
- case res
152
- when Net::HTTPSuccess
153
- response = JSON.parse res.body
154
- callback.complete(response)
155
- else
156
- res.error!
176
+ res = http.post(uri.path, invocation_signal.to_json, headers)
177
+
178
+ case res
179
+ when Net::HTTPSuccess
180
+ response = JSON.parse res.body
181
+ message.complete(response)
182
+ else
183
+ res.error!
184
+ end
185
+ rescue Timeout::Error
186
+ message.timeout
157
187
  end
158
- rescue Timeout::Error
159
- callback.timeout
188
+
189
+ message
160
190
  end
161
191
  end
162
192
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kimchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Gautier
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-15 00:00:00.000000000 Z
12
+ date: 2013-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler