diff options
author | John Keiser <john@johnkeiser.com> | 2015-05-28 13:05:46 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-05-28 13:27:44 -0700 |
commit | 81eaaa29cc175420e0ed6013cd2772b8941b65e7 (patch) | |
tree | f1d28b88f7c868c9bec112679a233150e7c9525d /lib/chef/client.rb | |
parent | f6ae5a3815cbcff6dbe0bbc66276e6929838ff9c (diff) | |
download | chef-81eaaa29cc175420e0ed6013cd2772b8941b65e7.tar.gz |
Move notification methods back to Client
Diffstat (limited to 'lib/chef/client.rb')
-rw-r--r-- | lib/chef/client.rb | 85 |
1 files changed, 83 insertions, 2 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 94aae15f03..b63671bd59 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -50,7 +50,6 @@ require 'chef/run_lock' require 'chef/policy_builder' require 'chef/request_id' require 'chef/platform/rebooter' -require 'chef/client/notification_registry' require 'chef/mixin/deprecation' require 'ohai' require 'rbconfig' @@ -62,7 +61,6 @@ class Chef class Client include Chef::Mixin::PathSanity - extend NotificationRegistry extend Chef::Mixin::Deprecation # @@ -766,6 +764,89 @@ class Chef end end + # Notification registration + class<<self + # + # Add a listener for the 'client run started' event. + # + # @param notification_block The callback (takes |run_status| parameter). + # @yieldparam [Chef::RunStatus] run_status The run status. + # + def when_run_starts(¬ification_block) + run_start_notifications << notification_block + end + + # + # Add a listener for the 'client run success' event. + # + # @param notification_block The callback (takes |run_status| parameter). + # @yieldparam [Chef::RunStatus] run_status The run status. + # + def when_run_completes_successfully(¬ification_block) + run_completed_successfully_notifications << notification_block + end + + # + # Add a listener for the 'client run failed' event. + # + # @param notification_block The callback (takes |run_status| parameter). + # @yieldparam [Chef::RunStatus] run_status The run status. + # + def when_run_fails(¬ification_block) + run_failed_notifications << notification_block + end + + # + # Clears all listeners for client run status events. + # + # Primarily for testing purposes. + # + # @api private + # + def clear_notifications + @run_start_notifications = nil + @run_completed_successfully_notifications = nil + @run_failed_notifications = nil + end + + # + # TODO These seem protected to me. + # + + # + # Listeners to be run when the client run starts. + # + # @return [Array<Proc>] + # + # @api private + # + def run_start_notifications + @run_start_notifications ||= [] + end + + # + # Listeners to be run when the client run completes successfully. + # + # @return [Array<Proc>] + # + # @api private + # + def run_completed_successfully_notifications + @run_completed_successfully_notifications ||= [] + end + + # + # Listeners to be run when the client run fails. + # + # @return [Array<Proc>] + # + # @api private + # + def run_failed_notifications + @run_failed_notifications ||= [] + end + end + # # IO stream that will be used as 'STDOUT' for formatters. Formatters are # configured during `initialize`, so this provides a convenience for |