diff options
author | Ranjib Dey <ranjib@pagerduty.com> | 2015-06-13 00:08:35 -0700 |
---|---|---|
committer | Ranjib Dey <ranjib@pagerduty.com> | 2015-06-13 00:24:02 -0700 |
commit | 0f642172350c9ce6297499d0619abdcd36921e9c (patch) | |
tree | 3907949e1035c6e9c53dc39d9a23808bb04589d0 /lib/chef/event_dispatch | |
parent | 414b3b2bea634c48f6c1996b0e7a5884cc3ad2c7 (diff) | |
download | chef-0f642172350c9ce6297499d0619abdcd36921e9c.tar.gz |
use Chef.run_context to register handler if set
Diffstat (limited to 'lib/chef/event_dispatch')
-rw-r--r-- | lib/chef/event_dispatch/dsl.rb | 10 |
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 |