Kris Rasmussen
added a comment - 12/Feb/09 1:48 AM I like that, but I'd suggest you accept an array as well so that the order is represented, or allow multiple notifies to be used in the same resource.

The fix provides the ability to notify different resources for different actions.

The new "notifies" method in resources.rb can either be used as the usual way (take 2 or 3 parameters), or take an array of hashes (of resources and actions). For the array of hashes, each element of the array is a hash with the resources as the key, and an array of 2 elements: action and timing as the value.

Added new notifies(*args) method:
1. raise ArgumentError if number of arguments passed in is greater than 3 or less than 1.
2. if the number of arguments is greater than 1 (and lass than 4), call the (original) notifies_helper method.
3. if the number of arguments is 1, it's an array of hashes. Process the hashes one by one and call the original notifies_helper method.

notify_different_resources_for_different_actions.rb - the recipe created for testing purpose

delayed_notifications.feature - Added Scenario: Notify different resources for different actions

Nuo Yan
added a comment - 27/Apr/09 11:50 PM Fixed.
The fix provides the ability to notify different resources for different actions.
The new "notifies" method in resources.rb can either be used as the usual way (take 2 or 3 parameters), or take an array of hashes (of resources and actions). For the array of hashes, each element of the array is a hash with the resources as the key, and an array of 2 elements: action and timing as the value.
Basically the syntax is like the following:
notifies ( [ {resources("execute[something]") => [:action, :timing]},
{resources("execute[something]") => [:action, :timing]},
{resources("execute[something]") => [:action, :timing]} ] )
For example:
execute "echo foo" do
notifies([{resources("file #{node[:tmpdir]}/notified_file_2.txt ") => [:create, :delayed] },
{resources("file #{node[:tmpdir]}/notified_file_3.txt ") => [:create, :delayed] }])
end
-----------
Files changed:
modified: chef/lib/chef/resource.rb
new file: features/data/cookbooks/delayed_notifications/recipes/notify_different_resources_for_different_actions.rb
modified: features/delayed_notifications.feature
Details:
resource.rb -
Changed the original notifies(action, resources, timing = :delayed) method to a private helper method notifies_helper(action, resources, timing=:delayed).
Added new notifies(*args) method:
1. raise ArgumentError if number of arguments passed in is greater than 3 or less than 1.
2. if the number of arguments is greater than 1 (and lass than 4), call the (original) notifies_helper method.
3. if the number of arguments is 1, it's an array of hashes. Process the hashes one by one and call the original notifies_helper method.
notify_different_resources_for_different_actions.rb - the recipe created for testing purpose
delayed_notifications.feature - Added Scenario: Notify different resources for different actions

Adam Jacob
added a comment - 18/May/09 9:22 PM I'm accepting this patch, but I want to point out that you can get the same functionality by repeating the notifies statement in a resource:
file "/tmp/foo" do
notifies :run, resources(:execute => 'bobo')
notifies :restart, resources(:service => 'apache2')
end
Even though that is true, some people might prefer the single call form... so patch accepted!
Nice work, Nuo.