combi 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: f32c087a7be58753b98c2453f2b30051eaf5abf5
4
- data.tar.gz: 0204a9e540356da36488b94166bc7b479f49f29c
3
+ metadata.gz: fb9c96c293e468a51e0e8df468cd80351c8527f1
4
+ data.tar.gz: 6dae3c02ff950edb7f344023b6d3d1c474b18984
5
5
  SHA512:
6
- metadata.gz: a7b26b16b375706f08da91f6e3fbdb3fa71423e2e3c9f1081a3f03ff65d1a1c1d9aa8ec1497311089f80fc2c57f61a1e72b741d8d59f0101b7755f5018276a13
7
- data.tar.gz: 3e1e5784274ab360b7b165901244da15bdb7df3dfc2d3530e6bead4308c6c42250fe38e170f4710d6c1ccf0090177db2aa83d27f9dbbfce392b6f5c9fc18c193
6
+ metadata.gz: 07a365af34ac3944d4b4233ce02c695cd81b2c3feeda634bb8d20708e560ef941ab8e5e40d1a0d6d62b278ac87e27471b111f13e79e7e2946b10eeb199db19fc
7
+ data.tar.gz: 99931424936890d9202d184d059266190e419ed7baa10874280a0ccc38920eae919625cdcca1812dc13e72e7b7161afd4fbf4f8c59b55c44a3ee2d37f62368c3
@@ -1,4 +1,5 @@
1
1
  require "combi/service"
2
+ require_relative 'correlation'
2
3
  require 'yajl'
3
4
  require 'yajl/json_gem' # for object.to_json, JSON.parse, etc...
4
5
 
@@ -7,7 +8,6 @@ module Combi
7
8
  attr_reader :services
8
9
 
9
10
  RPC_DEFAULT_TIMEOUT = 1
10
- RPC_MAX_POLLS = 10
11
11
 
12
12
  def initialize(options)
13
13
  @options = options
@@ -57,7 +57,7 @@ module Combi
57
57
 
58
58
  def log(message)
59
59
  return unless @debug_mode ||= ENV['DEBUG'] == 'true'
60
- puts "#{object_id} #{self.class.name} #{message}"
60
+ puts "#{Time.now.to_f} #{self.class.name} #{message}"
61
61
  end
62
62
 
63
63
  protected
@@ -0,0 +1,7 @@
1
+ module Combi
2
+ class Correlation
3
+ def self.generate
4
+ "#{Thread.current.object_id}_#{rand(10_000_000)}"
5
+ end
6
+ end
7
+ end
@@ -71,7 +71,7 @@ module Combi
71
71
  def request(name, kind, message, options = {})
72
72
  options[:timeout] ||= RPC_DEFAULT_TIMEOUT
73
73
 
74
- correlation_id = rand(10_000_000).to_s
74
+ correlation_id = Combi::Correlation.generate
75
75
  waiter = EventedWaiter.wait_for(correlation_id, @response_store, options[:timeout])
76
76
  url = "#{@options[:remote_api]}#{name}/#{kind}"
77
77
  request_async = EventMachine::HttpRequest.new(url, connection_timeout: options[:timeout]).post(body: message.to_json)
@@ -46,9 +46,10 @@ module Combi
46
46
  end
47
47
 
48
48
  def request(name, kind, message, options = {})
49
+ log "Preparing request: #{name}.#{kind} #{message.inspect}\t|| #{options.inspect}"
49
50
  options[:timeout] ||= RPC_DEFAULT_TIMEOUT
50
51
  options[:routing_key] = name.to_s
51
- correlation_id = rand(10_000_000).to_s
52
+ correlation_id = Combi::Correlation.generate
52
53
  options[:correlation_id] = correlation_id
53
54
  waiter = EventedWaiter.wait_for(correlation_id, @response_store, options[:timeout])
54
55
  queue_service.ready do
@@ -212,7 +212,7 @@ module Combi
212
212
  kind: kind,
213
213
  payload: message
214
214
  }
215
- correlation_id = rand(10_000_000).to_s
215
+ correlation_id = Combi::Correlation.generate
216
216
  msg[:correlation_id] = correlation_id
217
217
  waiter = EventedWaiter.wait_for(correlation_id, @response_store, options[:timeout])
218
218
  @ready.callback do |r|
@@ -4,14 +4,15 @@ module Combi
4
4
 
5
5
  def self.wait_for(defer, options = {}, &block)
6
6
  options[:timeout] ||= 2
7
- poll_time = options[:timeout] / 10
8
7
  resolved = false
8
+ waiter_thread = Thread.current
9
9
  defer.callback { |response|
10
10
  resolved = true
11
11
  block.call response
12
+ waiter_thread.wakeup
12
13
  }
13
14
  Timeout::timeout(options[:timeout]) do
14
- sleep poll_time while !resolved
15
+ Thread.stop
15
16
  end
16
17
  end
17
18
 
@@ -4,9 +4,6 @@ require 'amqp/utilities/event_loop_helper'
4
4
  module Combi
5
5
  class QueueService
6
6
 
7
- RPC_DEFAULT_TIMEOUT = 1
8
- RPC_WAIT_PERIOD = 0.01
9
-
10
7
  attr_accessor :rpc_callback
11
8
 
12
9
  def initialize(config, options)
@@ -22,7 +19,7 @@ module Combi
22
19
 
23
20
  def log(message)
24
21
  return unless @debug_mode ||= ENV['DEBUG'] == 'true'
25
- puts "#{object_id} #{self.class.name} #{message}"
22
+ puts "#{Time.now.to_f} #{self.class.name} #{message}"
26
23
  end
27
24
 
28
25
  def start
@@ -53,7 +50,10 @@ module Combi
53
50
 
54
51
  def publish(*args, &block)
55
52
  args[0] = args[0].to_json unless args[0].is_a? String
56
- @exchange.publish *args, &block
53
+ @exchange.publish *args do
54
+ log "Sent to network drivers: #{args.inspect}"
55
+ block.call if block_given?
56
+ end
57
57
  end
58
58
 
59
59
  def queue(name, options = {}, &block)
@@ -21,14 +21,22 @@ module Combi
21
21
 
22
22
  class EventedWaiter
23
23
  include EM::Deferrable
24
+ def self.log(message)
25
+ return unless @debug_mode ||= ENV['DEBUG'] == 'true'
26
+ puts "#{Time.now.to_f} #{self.name} #{message}"
27
+ end
24
28
 
25
29
  def self.wait_for(key, response_store, timeout)
26
- waiter = new(key, response_store, timeout, Combi::Bus::RPC_MAX_POLLS)
30
+ t1 = Time.now
31
+ log "started waiting for #{key}"
32
+ waiter = new(key, response_store, timeout)
27
33
  response_store.add_waiter(key, waiter)
34
+ waiter.callback {|r| log "success waiting for #{key}: #{Time.now.to_f - t1.to_f}s" }
35
+ waiter.errback {|r| log "failed waiting for #{key}: #{Time.now.to_f - t1.to_f}s, #{r.inspect}" }
28
36
  waiter
29
37
  end
30
38
 
31
- def initialize(key, response_store, timeout, max_polls)
39
+ def initialize(key, response_store, timeout)
32
40
  self.timeout(timeout, RuntimeError.new(Timeout::Error))
33
41
  end
34
42
 
@@ -1,3 +1,3 @@
1
1
  module Combi
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combi
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
  - German Del Zotto
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-01 00:00:00.000000000 Z
12
+ date: 2014-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
@@ -152,6 +152,7 @@ files:
152
152
  - combi.gemspec
153
153
  - lib/combi.rb
154
154
  - lib/combi/buses/bus.rb
155
+ - lib/combi/buses/correlation.rb
155
156
  - lib/combi/buses/http.rb
156
157
  - lib/combi/buses/in_process.rb
157
158
  - lib/combi/buses/queue.rb
@@ -195,9 +196,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
196
  version: '0'
196
197
  requirements: []
197
198
  rubyforge_project:
198
- rubygems_version: 2.2.0
199
+ rubygems_version: 2.2.2
199
200
  signing_key:
200
201
  specification_version: 4
201
202
  summary: Mini Bus for microservices
202
203
  test_files: []
203
- has_rdoc: