Class: Kdeploy::CommandExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/kdeploy/command_executor.rb

Overview

Executes a single command and records execution time

Instance Method Summary collapse

Constructor Details

#initialize(executor, output) ⇒ CommandExecutor

Returns a new instance of CommandExecutor.



6
7
8
9
# File 'lib/kdeploy/command_executor.rb', line 6

def initialize(executor, output)
  @executor = executor
  @output = output
end

Instance Method Details

#execute_run(command, host_name) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/kdeploy/command_executor.rb', line 11

def execute_run(command, host_name)
  show_command_header(host_name, :run, command[:command])
  result, duration = measure_time do
    @executor.execute(command[:command])
  end
  show_command_output(result)
  { command: command[:command], output: result, duration: duration, type: :run }
end

#execute_upload(command, host_name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kdeploy/command_executor.rb', line 20

def execute_upload(command, host_name)
  show_command_header(host_name, :upload, "#{command[:source]} -> #{command[:destination]}")
  _result, duration = measure_time do
    @executor.upload(command[:source], command[:destination])
  end
  {
    command: "upload: #{command[:source]} -> #{command[:destination]}",
    duration: duration,
    type: :upload
  }
end

#execute_upload_template(command, host_name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kdeploy/command_executor.rb', line 32

def execute_upload_template(command, host_name)
  show_command_header(host_name, :upload_template, "#{command[:source]} -> #{command[:destination]}")
  _result, duration = measure_time do
    @executor.upload_template(command[:source], command[:destination], command[:variables])
  end
  {
    command: "upload_template: #{command[:source]} -> #{command[:destination]}",
    duration: duration,
    type: :upload_template
  }
end