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.
48 49 50 |
# File 'lib/deploy/cli/websocket_client.rb', line 48 def initialize @subscriptions = {} end |
Instance Attribute Details
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
12 13 14 |
# File 'lib/deploy/cli/websocket_client.rb', line 12 def subscriptions @subscriptions end |
Instance Method Details
#run ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/deploy/cli/websocket_client.rb', line 57 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
52 53 54 55 |
# File 'lib/deploy/cli/websocket_client.rb', line 52 def subscribe(exchange, routing_key) key = subscription_key(exchange, routing_key) subscriptions[key] ||= Subscription.new(exchange, routing_key) end |