Class: Deploy::CLI::DeploymentProgressOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy/cli/deployment_progress_output.rb

Constant Summary collapse

SERVER_TAG_COLOURS =
%w[32 33 34 35 36].cycle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deployment) ⇒ DeploymentProgressOutput

Returns a new instance of DeploymentProgressOutput.



8
9
10
11
12
13
14
15
# File 'lib/deploy/cli/deployment_progress_output.rb', line 8

def initialize(deployment)
  @deployment = deployment

  @step_index = @deployment.steps.each_with_object({}) { |s, hsh| hsh[s.identifier] = s }
  @server_tags = @deployment.servers.each_with_object({}) do |s, hsh|
    hsh[s.id] = "\e[#{SERVER_TAG_COLOURS.next};1m[#{s.name}]\e[0m "
  end
end

Instance Attribute Details

#deploymentObject (readonly)

Returns the value of attribute deployment.



6
7
8
# File 'lib/deploy/cli/deployment_progress_output.rb', line 6

def deployment
  @deployment
end

#server_tagsObject (readonly)

Returns the value of attribute server_tags.



6
7
8
# File 'lib/deploy/cli/deployment_progress_output.rb', line 6

def server_tags
  @server_tags
end

#step_indexObject (readonly)

Returns the value of attribute step_index.



6
7
8
# File 'lib/deploy/cli/deployment_progress_output.rb', line 6

def step_index
  @step_index
end

Instance Method Details

#monitorObject



17
18
19
20
21
22
23
24
25
# File 'lib/deploy/cli/deployment_progress_output.rb', line 17

def monitor
  websocket_client = Deploy::CLI::WebsocketClient.new

  subscription = websocket_client.subscribe('deployment', @deployment.identifier)
  subscription.on('log-entry', &method(:handle_log_entry))
  subscription.on('status-change', &method(:handle_status_change))

  websocket_client.run
end