Class: Deploy::CLI::WebsocketClient

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeWebsocketClient

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

#subscriptionsObject (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

#runObject



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.onmessage 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