Class: Chef::RunStatus
Overview
Chef::RunStatus
Tracks various aspects of a Chef run, including the Node and RunContext, start and end time, and any Exception that stops the run. RunStatus objects are passed to any notification or exception handlers at the completion of a Chef run.
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#run_context ⇒ Object
Returns the value of attribute run_context.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#all_resources ⇒ Object
The list of all resources in the current run context’s
resource_collection
. -
#backtrace ⇒ Object
The backtrace from
exception
, if any. -
#elapsed_time ⇒ Object
The elapsed time between
start_time
andend_time
. -
#failed? ⇒ Boolean
Did the Chef run fail?.
-
#formatted_exception ⇒ Object
Returns a string of the format “ExceptionClass: message” or
nil
if noexception
is set. -
#initialize(node, events) ⇒ RunStatus
constructor
A new instance of RunStatus.
- #node ⇒ Object
-
#start_clock ⇒ Object
sets
start_time
to the current time. -
#stop_clock ⇒ Object
sets
end_time
to the current time. -
#success? ⇒ Boolean
Did the chef run succeed? returns
true
if no exception has been set. -
#to_hash ⇒ Object
A Hash representation of the RunStatus, with the following (Symbol) keys: * :node * :success * :start_time * :end_time * :elapsed_time * :all_resources * :updated_resources * :exception * :backtrace.
-
#updated_resources ⇒ Object
The list of all resources in the current run context’s
resource_collection
that are marked as updated.
Constructor Details
#initialize(node, events) ⇒ RunStatus
Returns a new instance of RunStatus.
40 41 42 43 |
# File 'lib/chef/run_status.rb', line 40 def initialize(node, events) @node = node @events = events end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
34 35 36 |
# File 'lib/chef/run_status.rb', line 34 def end_time @end_time end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
26 27 28 |
# File 'lib/chef/run_status.rb', line 26 def events @events end |
#exception ⇒ Object
Returns the value of attribute exception.
36 37 38 |
# File 'lib/chef/run_status.rb', line 36 def exception @exception end |
#run_context ⇒ Object
Returns the value of attribute run_context.
28 29 30 |
# File 'lib/chef/run_status.rb', line 28 def run_context @run_context end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
32 33 34 |
# File 'lib/chef/run_status.rb', line 32 def start_time @start_time end |
Instance Method Details
#all_resources ⇒ Object
The list of all resources in the current run context’s resource_collection
70 71 72 |
# File 'lib/chef/run_status.rb', line 70 def all_resources @run_context && @run_context.resource_collection.all_resources end |
#backtrace ⇒ Object
The backtrace from exception
, if any
81 82 83 |
# File 'lib/chef/run_status.rb', line 81 def backtrace @exception && @exception.backtrace end |
#elapsed_time ⇒ Object
The elapsed time between start_time
and end_time
. Returns nil
if either value is not set.
61 62 63 64 65 66 67 |
# File 'lib/chef/run_status.rb', line 61 def elapsed_time if @start_time && @end_time @end_time - @start_time else nil end end |
#failed? ⇒ Boolean
Did the Chef run fail?
86 87 88 |
# File 'lib/chef/run_status.rb', line 86 def failed? !success? end |
#formatted_exception ⇒ Object
Returns a string of the format “ExceptionClass: message” or nil
if no exception
is set.
120 121 122 |
# File 'lib/chef/run_status.rb', line 120 def formatted_exception @exception && "#{@exception.class.name}: #{@exception.}" end |
#node ⇒ Object
45 46 47 |
# File 'lib/chef/run_status.rb', line 45 def node @node end |
#start_clock ⇒ Object
sets start_time
to the current time.
50 51 52 |
# File 'lib/chef/run_status.rb', line 50 def start_clock @start_time = Time.now end |
#stop_clock ⇒ Object
sets end_time
to the current time
55 56 57 |
# File 'lib/chef/run_status.rb', line 55 def stop_clock @end_time = Time.now end |
#success? ⇒ Boolean
Did the chef run succeed? returns true
if no exception has been set.
91 92 93 |
# File 'lib/chef/run_status.rb', line 91 def success? @exception.nil? end |
#to_hash ⇒ Object
A Hash representation of the RunStatus, with the following (Symbol) keys:
-
:node
-
:success
-
:start_time
-
:end_time
-
:elapsed_time
-
:all_resources
-
:updated_resources
-
:exception
-
:backtrace
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/chef/run_status.rb', line 105 def to_hash # use a flat hash here so we can't errors from intermediate values being nil { :node => node, :success => success?, :start_time => start_time, :end_time => end_time, :elapsed_time => elapsed_time, :all_resources => all_resources, :updated_resources => updated_resources, :exception => formatted_exception, :backtrace => backtrace} end |
#updated_resources ⇒ Object
The list of all resources in the current run context’s resource_collection
that are marked as updated
76 77 78 |
# File 'lib/chef/run_status.rb', line 76 def updated_resources @run_context && @run_context.resource_collection.select { |r| r.updated } end |