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.



41
42
43
# File 'lib/deploy/cli/websocket_client.rb', line 41

def initialize
  @subscriptions = {}
end

Instance Attribute Details

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

#runObject



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



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