Class: Deploy::CLI::WebsocketClient
- Inherits:
-
Object
- Object
- Deploy::CLI::WebsocketClient
- Defined in:
- lib/deploy/cli/websocket_client.rb
Overview
Manages a connection and associated subscriptions to DeployHQ’s websocket
Defined Under Namespace
Classes: Subscription
Instance Attribute Summary collapse
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
Instance Method Summary collapse
-
#initialize ⇒ WebsocketClient
constructor
A new instance of WebsocketClient.
- #run ⇒ Object
- #subscribe(exchange, routing_key) ⇒ Object
Constructor Details
#initialize ⇒ WebsocketClient
Returns a new instance of WebsocketClient.
41 42 43 |
# File 'lib/deploy/cli/websocket_client.rb', line 41 def initialize @subscriptions = {} end |
Instance Attribute Details
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
8 9 10 |
# File 'lib/deploy/cli/websocket_client.rb', line 8 def subscriptions @subscriptions end |
Instance Method Details
#run ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/deploy/cli/websocket_client.rb', line 50 def run catch(:finished) do EM.run do connection.onopen do logger.info "connected" end connection. do |msg, type| receive(msg) end connection.onclose do |code, reason| logger.info "disconnected #{code} #{reason}" reset_connection end end end end |
#subscribe(exchange, routing_key) ⇒ Object
45 46 47 48 |
# File 'lib/deploy/cli/websocket_client.rb', line 45 def subscribe(exchange, routing_key) key = subscription_key(exchange, routing_key) subscriptions[key] ||= Subscription.new(exchange, routing_key) end |