Class: Profit::Client
- Inherits:
-
Object
- Object
- Profit::Client
- Defined in:
- lib/profit/client.rb
Instance Attribute Summary collapse
-
#ctx ⇒ Object
Returns the value of attribute ctx.
-
#pending ⇒ Object
Returns the value of attribute pending.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #socket ⇒ Object
- #start(metric_key) ⇒ Object
- #stop(metric_key) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 |
# File 'lib/profit/client.rb', line 11 def initialize( = {}) @ctx = [:ctx] || ZMQ::Context.new @server_address = [:server_address] || "tcp://127.0.0.1:5556" @pending = {} end |
Instance Attribute Details
#ctx ⇒ Object
Returns the value of attribute ctx.
9 10 11 |
# File 'lib/profit/client.rb', line 9 def ctx @ctx end |
#pending ⇒ Object
Returns the value of attribute pending.
9 10 11 |
# File 'lib/profit/client.rb', line 9 def pending @pending end |
Instance Method Details
#socket ⇒ Object
35 36 37 |
# File 'lib/profit/client.rb', line 35 def socket Thread.current[:socket] ||= @ctx.connect(:PUSH, @server_address) end |
#start(metric_key) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/profit/client.rb', line 17 def start(metric_key) pending_key = pending_key_for(Key.new(metric_key).to_s) metric = Metric.new(metric_key: metric_key, start_line: caller[0], start_time: Time.now) pending[pending_key] = metric end |
#stop(metric_key) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/profit/client.rb', line 26 def stop(metric_key) pending_key = pending_key_for(Key.new(metric_key).to_s) metric = pending.delete pending_key metric.recorded_time = Time.now - metric.start_time metric.stop_line = caller[0] socket.send(metric.to_json) end |