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
Source
# File lib/chef/run_status.rb, line 40 def initialize(node, events) @node = node @events = events end
Public Instance Methods
Source
# File lib/chef/run_status.rb, line 67 def all_resources @run_context && @run_context.resource_collection.all_resources end
The list of all resources in the current run context’s resource_collection
Source
# File lib/chef/run_status.rb, line 78 def backtrace @exception && @exception.backtrace end
The backtrace from exception
, if any
Source
# File lib/chef/run_status.rb, line 58 def elapsed_time if @start_time && @end_time @end_time - @start_time else nil end end
The elapsed time between start_time
and end_time
. Returns nil
if either value is not set.
Source
# File lib/chef/run_status.rb, line 83 def failed? !success? end
Did the Chef
run fail?
Source
# File lib/chef/run_status.rb, line 120 def formatted_exception @exception && "#{@exception.class.name}: #{@exception.message}" end
Returns a string of the format “ExceptionClass: message” or nil
if no exception
is set.
Source
# File lib/chef/run_status.rb, line 46 def start_clock @start_time = Time.now end
sets start_time
to the current time.
Source
# File lib/chef/run_status.rb, line 51 def stop_clock @start_time ||= Time.now # if we failed so early we didn't get a start time @end_time = Time.now end
sets end_time
to the current time
Source
# File lib/chef/run_status.rb, line 88 def success? @exception.nil? end
Did the chef run succeed? returns true
if no exception has been set.
Source
# File lib/chef/run_status.rb, line 102 def to_h # 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
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
Source
# File lib/chef/run_status.rb, line 73 def updated_resources @run_context && @run_context.resource_collection.select(&:updated) end
The list of all resources in the current run context’s resource_collection
that are marked as updated