Class: Kdeploy::Task
- Inherits:
-
Object
- Object
- Kdeploy::Task
- Defined in:
- lib/kdeploy/task.rb
Overview
Task class for managing command execution on hosts
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#global_variables ⇒ Object
Returns the value of attribute global_variables.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#add_command(name, command, options = {}) ⇒ Command
Add command to task.
-
#add_host(host) ⇒ Host
Add host to task.
-
#execute ⇒ Hash
Execute task on all hosts.
-
#initialize(name, hosts = [], options = {}) ⇒ Task
constructor
A new instance of Task.
-
#remove_host(host) ⇒ Host?
Remove host from task.
Constructor Details
#initialize(name, hosts = [], options = {}) ⇒ Task
Returns a new instance of Task.
9 10 11 12 13 14 15 |
# File 'lib/kdeploy/task.rb', line 9 def initialize(name, hosts = [], = {}) @name = name @hosts = Array(hosts) @commands = [] @options = .merge() @global_variables = {} end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
6 7 8 |
# File 'lib/kdeploy/task.rb', line 6 def commands @commands end |
#global_variables ⇒ Object
Returns the value of attribute global_variables.
7 8 9 |
# File 'lib/kdeploy/task.rb', line 7 def global_variables @global_variables end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
6 7 8 |
# File 'lib/kdeploy/task.rb', line 6 def hosts @hosts end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/kdeploy/task.rb', line 6 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/kdeploy/task.rb', line 6 def @options end |
Instance Method Details
#add_command(name, command, options = {}) ⇒ Command
Add command to task
22 23 24 25 26 27 |
# File 'lib/kdeploy/task.rb', line 22 def add_command(name, command, = {}) = .merge(global_variables: @global_variables) cmd = Command.new(name, command, ) @commands << cmd cmd end |
#add_host(host) ⇒ Host
Add host to task
32 33 34 35 |
# File 'lib/kdeploy/task.rb', line 32 def add_host(host) @hosts << host unless @hosts.include?(host) host end |
#execute ⇒ Hash
Execute task on all hosts
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kdeploy/task.rb', line 46 def execute return empty_execution_result if @commands.empty? || @hosts.empty? log_task_start start_time = Time.now results = execute_commands duration = Time.now - start_time success_count = count_successful_hosts(results) log_task_completion(duration, success_count) build_task_result(results, duration, success_count) end |
#remove_host(host) ⇒ Host?
Remove host from task
40 41 42 |
# File 'lib/kdeploy/task.rb', line 40 def remove_host(host) @hosts.delete(host) end |