Class: MCollective::Util::Playbook::TaskResult

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/util/playbook/task_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ TaskResult

Returns a new instance of TaskResult.



7
8
9
10
11
12
13
# File 'lib/mcollective/util/playbook/task_result.rb', line 7

def initialize(task)
  @start_time = Time.now
  @end_time = @start_time
  @ran = false
  @task = task
  @description = task[:description]
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def data
  @data
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def description
  @description
end

#end_timeObject

Returns the value of attribute end_time.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def end_time
  @end_time
end

#msgObject

Returns the value of attribute msg.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def msg
  @msg
end

#ranObject

Returns the value of attribute ran.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def ran
  @ran
end

#setObject

Returns the value of attribute set.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def set
  @set
end

#start_timeObject

Returns the value of attribute start_time.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def start_time
  @start_time
end

#successObject

Returns the value of attribute success.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def success
  @success
end

#taskObject

Returns the value of attribute task.



5
6
7
# File 'lib/mcollective/util/playbook/task_result.rb', line 5

def task
  @task
end

Instance Method Details

#run_timeObject



19
20
21
# File 'lib/mcollective/util/playbook/task_result.rb', line 19

def run_time
  @end_time - @start_time
end

#success?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/mcollective/util/playbook/task_result.rb', line 23

def success?
  !!success
end

#task_typeObject



15
16
17
# File 'lib/mcollective/util/playbook/task_result.rb', line 15

def task_type
  @task[:type]
end

#timed_run(set) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mcollective/util/playbook/task_result.rb', line 27

def timed_run(set)
  @start_time = Time.now
  @set = set

  begin
    @success, @msg, @data = task[:runner].run

    if !@success && task[:properties]["fail_ok"] && task[:properties]["tries"] == 1
      Log.warn("Task failed but fail_ok is true, treating as success")
      @success = true
    end
  rescue
    @success = false
    @data = [$!]
    @msg = "Running task %s failed unexpectedly: %s: %s" % [task.to_s, $!.class, $!.to_s]

    Log.warn(@msg)
    Log.debug($!.backtrace.join("\n\t"))
  end

  @end_time = Time.now
  @ran = true

  self
end