class Chef::RunStatus
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.
Attributes
Public Class Methods
# File lib/chef/run_status.rb, line 44 def initialize(node, events) @node = node @events = events end
Public Instance Methods
The list of all resources in the current run context's
resource_collection
# File lib/chef/run_status.rb, line 70 def all_resources @run_context && @run_context.resource_collection.all_resources end
The backtrace from exception
, if any
# File lib/chef/run_status.rb, line 81 def backtrace @exception && @exception.backtrace end
The elapsed time between start_time
and end_time
.
Returns nil
if either value is not set.
# File lib/chef/run_status.rb, line 61 def elapsed_time if @start_time && @end_time @end_time - @start_time else nil end end
Did the Chef run fail?
# File lib/chef/run_status.rb, line 86 def failed? !success? end
Returns a string of the format “ExceptionClass: message” or
nil
if no exception
is set.
# File lib/chef/run_status.rb, line 121 def formatted_exception @exception && "#{@exception.class.name}: #{@exception.message}" end
sets start_time
to the current time.
# File lib/chef/run_status.rb, line 50 def start_clock @start_time = Time.now end
sets end_time
to the current time
# File lib/chef/run_status.rb, line 55 def stop_clock @end_time = Time.now end
Did the chef run succeed? returns true
if no exception has
been set.
# File lib/chef/run_status.rb, line 91 def success? @exception.nil? end
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
# 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, :run_id => run_id } end
The list of all resources in the current run context's
resource_collection
that are marked as updated
# File lib/chef/run_status.rb, line 76 def updated_resources @run_context && @run_context.resource_collection.select { |r| r.updated } end