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.



14
15
16
17
18
19
20
21
# File 'lib/deploy/cli/deployment_progress_output.rb', line 14

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.



10
11
12
# File 'lib/deploy/cli/deployment_progress_output.rb', line 10

def deployment
  @deployment
end

#server_tagsObject (readonly)

Returns the value of attribute server_tags.



12
13
14
# File 'lib/deploy/cli/deployment_progress_output.rb', line 12

def server_tags
  @server_tags
end

#step_indexObject (readonly)

Returns the value of attribute step_index.



11
12
13
# File 'lib/deploy/cli/deployment_progress_output.rb', line 11

def step_index
  @step_index
end

Instance Method Details

#monitorObject



23
24
25
26
27
28
29
30
31
# File 'lib/deploy/cli/deployment_progress_output.rb', line 23

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