summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRanjib Dey <ranjib@pagerduty.com>2015-06-13 00:08:35 -0700
committerRanjib Dey <ranjib@pagerduty.com>2015-06-13 00:24:02 -0700
commit0f642172350c9ce6297499d0619abdcd36921e9c (patch)
tree3907949e1035c6e9c53dc39d9a23808bb04589d0
parent414b3b2bea634c48f6c1996b0e7a5884cc3ad2c7 (diff)
downloadchef-0f642172350c9ce6297499d0619abdcd36921e9c.tar.gz
use Chef.run_context to register handler if set
-rw-r--r--lib/chef/event_dispatch/dsl.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/event_dispatch/dsl.rb b/lib/chef/event_dispatch/dsl.rb
index f61ea90580..6e5178f20b 100644
--- a/lib/chef/event_dispatch/dsl.rb
+++ b/lib/chef/event_dispatch/dsl.rb
@@ -32,7 +32,15 @@ class Chef
handler.define_singleton_method(event_type) do |*args|
block.call(args)
end
- Chef::Config[:event_handlers] << handler
+ # Use current event dispacth system is run_context and associated event
+ # dispatcher is set else fall back to Chef::Config[:hanlder]
+ if Chef.run_context && Chef.run_context.events
+ Chef::Log.debug('Registering handler using run_context')
+ Chef.run_context.events.register(handler)
+ else
+ Chef::Log.debug('Registering handler using config, this will only work inside config file')
+ Chef::Config[:event_handlers] << handler
+ end
handler
end