Class: Kdeploy::CommandExecutor
- Inherits:
-
Object
- Object
- Kdeploy::CommandExecutor
- Defined in:
- lib/kdeploy/command_executor.rb
Overview
Executes a single command and records execution time
Instance Method Summary collapse
- #execute_run(command, _host_name) ⇒ Object
- #execute_sync(command, _host_name) ⇒ Object
- #execute_upload(command, _host_name) ⇒ Object
- #execute_upload_template(command, _host_name) ⇒ Object
-
#initialize(executor, output, debug: false, retries: 0, retry_delay: 1) ⇒ CommandExecutor
constructor
A new instance of CommandExecutor.
Constructor Details
#initialize(executor, output, debug: false, retries: 0, retry_delay: 1) ⇒ CommandExecutor
Returns a new instance of CommandExecutor.
6 7 8 9 10 11 12 |
# File 'lib/kdeploy/command_executor.rb', line 6 def initialize(executor, output, debug: false, retries: 0, retry_delay: 1) @executor = executor @output = output @debug = debug @retries = retries.to_i @retry_delay = retry_delay.to_f end |
Instance Method Details
#execute_run(command, _host_name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kdeploy/command_executor.rb', line 14 def execute_run(command, _host_name) cmd = command[:command] use_sudo = command[:sudo] result, duration = measure_time do with_retries { @executor.execute(cmd, use_sudo: use_sudo) } end { command: cmd, output: result, duration: duration, type: :run } end |
#execute_sync(command, _host_name) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kdeploy/command_executor.rb', line 49 def execute_sync(command, _host_name) source = command[:source] destination = command[:destination] result, duration = measure_time do with_retries do @executor.sync_directory( source, destination, ignore: command[:ignore] || [], exclude: command[:exclude] || [], delete: command[:delete] || false ) end end build_sync_result(source, destination, result, duration) end |
#execute_upload(command, _host_name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kdeploy/command_executor.rb', line 25 def execute_upload(command, _host_name) _result, duration = measure_time do with_retries { @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
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kdeploy/command_executor.rb', line 36 def execute_upload_template(command, _host_name) _result, duration = measure_time do with_retries do @executor.upload_template(command[:source], command[:destination], command[:variables]) end end { command: "upload_template: #{command[:source]} -> #{command[:destination]}", duration: duration, type: :upload_template } end |