diff options
author | Ranjib Dey <dey.ranjib@gmail.com> | 2013-07-25 12:31:15 -0700 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-11-06 09:13:47 -0800 |
commit | 19511dbd2f3054752e3013c0853dc5cc9951033a (patch) | |
tree | df0d9cb48b6308cb90b251b3fb24cac7f659d8f5 | |
parent | de0b38de4c74a354477d841a66c604f92e647450 (diff) | |
download | chef-19511dbd2f3054752e3013c0853dc5cc9951033a.tar.gz |
compute elapsed time without altering public api
-rw-r--r-- | lib/chef/client.rb | 4 | ||||
-rw-r--r-- | lib/chef/event_dispatch/base.rb | 4 | ||||
-rw-r--r-- | lib/chef/formatters/doc.rb | 13 | ||||
-rw-r--r-- | lib/chef/formatters/minimal.rb | 8 | ||||
-rw-r--r-- | lib/chef/resource_reporter.rb | 4 |
5 files changed, 21 insertions, 12 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index da9c6f1b77..30b714cded 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -504,7 +504,7 @@ class Chef run_status.stop_clock Chef::Log.info("Chef Run complete in #{run_status.elapsed_time} seconds") run_completed_successfully - @events.run_completed(node, run_status.elapsed_time) + @events.run_completed(node) true rescue Exception => e # CHEF-3336: Send the error first in case something goes wrong below and we don't know why @@ -516,7 +516,7 @@ class Chef run_failed end Chef::Application.debug_stacktrace(e) - @events.run_failed(e, run_status.elapsed_time) + @events.run_failed(e) raise ensure @run_status = nil diff --git a/lib/chef/event_dispatch/base.rb b/lib/chef/event_dispatch/base.rb index 1e4deeb694..82beefeec9 100644 --- a/lib/chef/event_dispatch/base.rb +++ b/lib/chef/event_dispatch/base.rb @@ -36,11 +36,11 @@ class Chef end # Called at the end a successful Chef run. - def run_completed(node, elapsed_time) + def run_completed(node) end # Called at the end of a failed Chef run. - def run_failed(exception, elapsed_time) + def run_failed(exception) end # Called right after ohai runs. diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb index fb3903d0f0..ae1e6e3639 100644 --- a/lib/chef/formatters/doc.rb +++ b/lib/chef/formatters/doc.rb @@ -8,19 +8,27 @@ class Chef # "specdoc" class Doc < Formatters::Base + attr_reader :start_time, :end_time cli_name(:doc) + def initialize(out, err) super @updated_resources = 0 + @start_time = Time.now + end + + def elapsed_time + end_time - start_time end def run_start(version) puts "Starting Chef Client, version #{version}" end - def run_completed(node, elapsed_time) + def run_completed(node) + @end_time = Time.now if Chef::Config[:why_run] puts "Chef Client finished, #{@updated_resources} resources would have been updated" else @@ -28,7 +36,8 @@ class Chef end end - def run_failed(exception, elapsed_time) + def run_failed(exception) + @end_time = Time.now if Chef::Config[:why_run] puts "Chef Client failed. #{@updated_resources} resources would have been updated" else diff --git a/lib/chef/formatters/minimal.rb b/lib/chef/formatters/minimal.rb index bf52a9bebe..a189cc67eb 100644 --- a/lib/chef/formatters/minimal.rb +++ b/lib/chef/formatters/minimal.rb @@ -33,13 +33,13 @@ class Chef end # Called at the end of the Chef run. - def run_completed(node, elapsed_time) - puts "chef client finished, #{@updated_resources.size} resources updated in #{elapsed_time} seconds" + def run_completed(node) + puts "chef client finished, #{@updated_resources.size} resources updated" end # called at the end of a failed run - def run_failed(exception, elapsed_time) - puts "chef client failed. #{@updated_resources.size} resources updated in #{elapsed_time} seconds" + def run_failed(exception) + puts "chef client failed. #{@updated_resources.size} resources updated" end # Called right after ohai runs. diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index 2727084018..d29949086e 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -196,12 +196,12 @@ class Chef end end - def run_completed(node, elapsed_time) + def run_completed(node) @status = "success" post_reporting_data end - def run_failed(exception, elapsed_time) + def run_failed(exception) @exception = exception @status = "failure" # If we failed before we received the run_started callback, there's not much we can do |