-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows_task will not 'notify' other resources #271
Comments
Two work arounds: If the script that the task runs is extremely quick, you can do this.
However this has a huge limitation that if your script takes more than a second or two to run, then it will be deleted before it finishes. A better workaround is this:
It seems that |
Hi, my response is late but I hope this helps someone out. If the windows_task resource task_name attribute is not specified then the task_name is defaulted to the resource name. Therefore in your example windows_task 'foobar' is the name of the resource and also the task_name. In load_current_resource the task_name is changed (see below) The @new_resource.task_name.prepend('') is adding two slashes to the @resource.task_name. Normally in Ruby when the underlying object is changed a method is marked with a bang to signify warning, it's not obvious but prepend appears to change the underlying object. When the windows_task LWRP has finished executing if there were any actions the Chef::Runner will try and locate the resource in the resource queue to establish whether it should also action any notifications. My belief is that the name of the resource has changed and now includes two backslashes (), the resource cannot be found in the resource queue, which is why the notifications are failing. Can you try your code specifying the task_name and making it different from the resource name, e.g |
Thanks for the response. I see now that the reason this happens is because the resource name is not the same as the task name. So basically the following will fail to send notifications windows_task 'chef ad-join' do
user 'SYSTEM'
command 'chef-client'
notifies :create, 'file[c:/notifytest.txt]', :immediately # Notification fails
action :create
end Where as this will work properly windows_task 'chef ad-join' do
task_name 'foobar'
user 'SYSTEM'
command 'chef-client'
notifies :create, 'file[c:/notifytest.txt]', :immediately # Notification works
action :create
end I still think a change needs to be made to the cookbook since this is an easy trap to fall into (It bit me twice). The task_name parameter needs to be made mandatory. |
Thanks for confirming. It's a bug in the windows_taks resource, the resource name gets changed in load_current_resource hence why Chef::Runner can't locate resources in the notification queue. I can't make any fixes at the moment as we don't have a CLA. The error is to do with the use of the prepend method, this changes the underlying object, e.g x = 'hello' By the way I've only spotted some of the more involved resource issues thanks to pry or by applying a monkey patch with break points. |
If i'm understanding correctly, String.prepend in ruby creates another object. I don't quite see that. irb
2.2.0 :013 > puts foo.object_id
70161858505360
2.2.0 :014 > puts foo.prepend("\\")
\\abcd
2.2.0 :015 > puts foo.object_id
70161858505360 I"m guessing a solution might be to change this line:
to something like this? if @new_resource.task_name[0, 1] == '\\' do
@new_resource.task_name
else
new_name = "\\#{@new_resource.task_name}"
@new_resource.task_name = new_name
end
This is just a stab in the dark. I'll need to do more testing. I do have an CLA so if this works, i'll open a pull request. |
wow. You'd think |
👍 Manually verified against edee5a7 confirmed working |
fixes #271 making notify work for windows_task
If you have a scheduled task, and you attempt to delete it with ':delayed' it will never be deleted.
Example
Windows 2012 R2
Chef 12.4.1
Windows cookbook 1.38.1
The text was updated successfully, but these errors were encountered: