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

end_time[R]
events[R]
exception[RW]
node[RW]
run_context[RW]
run_id[RW]
start_time[R]

Public Class Methods

new(node, events) click to toggle source
# File lib/chef/run_status.rb, line 40
def initialize(node, events)
  @node = node
  @events = events
end

Public Instance Methods

all_resources() click to toggle source

The list of all resources in the current run context's resource_collection

# File lib/chef/run_status.rb, line 67
def all_resources
  @run_context && @run_context.resource_collection.all_resources
end
backtrace() click to toggle source

The backtrace from exception, if any

# File lib/chef/run_status.rb, line 78
def backtrace
  @exception && @exception.backtrace
end
elapsed_time() click to toggle source

The elapsed time between start_time and end_time. Returns nil if either value is not set.

# File lib/chef/run_status.rb, line 58
def elapsed_time
  if @start_time && @end_time
    @end_time - @start_time
  else
    nil
  end
end
failed?() click to toggle source

Did the Chef run fail?

# File lib/chef/run_status.rb, line 83
def failed?
  !success?
end
formatted_exception() click to toggle source

Returns a string of the format “ExceptionClass: message” or nil if no exception is set.

# File lib/chef/run_status.rb, line 120
def formatted_exception
  @exception && "#{@exception.class.name}: #{@exception.message}"
end
start_clock() click to toggle source

sets start_time to the current time.

# File lib/chef/run_status.rb, line 46
def start_clock
  @start_time = Time.now
end
stop_clock() click to toggle source

sets end_time to the current time

# 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
success?() click to toggle source

Did the chef run succeed? returns true if no exception has been set.

# File lib/chef/run_status.rb, line 88
def success?
  @exception.nil?
end
to_h() click to toggle source

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 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
Also aliased as: to_hash
to_hash()
Alias for: to_h
updated_resources() click to toggle source

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 73
def updated_resources
  @run_context && @run_context.resource_collection.select(&:updated)
end