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.
- checksums.yaml +4 -4
- data/lib/kimchi/version.rb +1 -1
- data/lib/wire.rb +52 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5654ac8ca0de9106fded06aca9f0191d7e470843
|
4
|
+
data.tar.gz: 865917d2156790f803f631aa93ce448f2134df2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cec8f80cac3960fbc2be24be6ba42cca3f52c2aa99343c095b2bc4df867a2a0f7f4c25255f8d4cbbbaae56938d9fa6b79c57684d88791a42a1a0f866f578d9c9
|
7
|
+
data.tar.gz: b3cbbdd7d9b552ebb93b77a7f90c4ba474799a19799c2f21ae28daa2ab58d2d4fdd24d9707f6fe08a3d92658e125baa93cd6173d3da9c45380299e54f3085ec0
|
data/lib/kimchi/version.rb
CHANGED
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,
|
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,
|
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,
|
137
|
-
|
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
|
-
|
143
|
-
|
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
|
-
|
146
|
-
|
147
|
-
invocation_signal.contexts = context_hash
|
169
|
+
invocation_signal.function.service = service_name
|
170
|
+
invocation_signal.function.version = version
|
148
171
|
|
149
|
-
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
159
|
-
|
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.
|
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-
|
12
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|