# 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]
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 42
    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 72
    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 83
    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 63
    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 88
    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 123
    def formatted_exception
      @exception && "#{@exception.class.name}: #{@exception.message}"
    end

node() click to toggle source

    # File lib/chef/run_status.rb, line 47
    def node
      @node
    end

start_clock() click to toggle source

sets `start_time` to the current time.

    # File lib/chef/run_status.rb, line 52
    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 57
    def stop_clock
      @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 93
    def success?
      @exception.nil?
    end

to_hash() 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 107
    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

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 78
    def updated_resources
      @run_context && @run_context.resource_collection.select { |r| r.updated }
    end