Creating a delayed action from a ruby_block

Howdy, all –

I have a ruby_block in which I do some comparison of file mtimes at
execution time, and – depending on the result – may or may not wish to
trigger a delayed action.

Thing is… what’s the syntax to do so? This is in Chef 0.10, and the
targeted resource hasn’t been declared yet at the time (so the old-style
references, as I understand it, aren’t yet available).

Thanks!

Try the:

notifies :foo, "resource[bar]", :delayed
On Aug 1, 2011 10:48 AM, "Charles Duffy" charles@dyfis.net wrote:

Howdy, all --

I have a ruby_block in which I do some comparison of file mtimes at
execution time, and -- depending on the result -- may or may not wish to
trigger a delayed action.

Thing is... what's the syntax to do so? This is in Chef 0.10, and the
targeted resource hasn't been declared yet at the time (so the old-style
references, as I understand it, aren't yet available).

Thanks!

If you use an LWRP instead of a Ruby block it might be a bit easier, since then you just don't trigger the updated_by_last_whatever if not needed.

--Noah

On Aug 1, 2011, at 10:47 AM, Charles Duffy wrote:

Howdy, all --

I have a ruby_block in which I do some comparison of file mtimes at execution time, and -- depending on the result -- may or may not wish to trigger a delayed action.

Thing is... what's the syntax to do so? This is in Chef 0.10, and the targeted resource hasn't been declared yet at the time (so the old-style references, as I understand it, aren't yet available).

Thanks!

AJ,

Thank you very much! I was operating under a belief that "notifies" was for
compile-time use only, but it does appear to work at execution time as
well.

That said, there are some caveats:

notifies :restart, "service[shorewall]", :delayed

fails with:

NoMethodError: undefined method `run_action' for

"service[shorewall]":String

However,

notifies :restart, resources(:service => "shorewall")

does The Right Thing.

On Mon, Aug 1, 2011 at 12:52 PM, AJ Christensen aj@junglist.gen.nz wrote:

Try the:

notifies :foo, "resource[bar]", :delayed
On Aug 1, 2011 10:48 AM, "Charles Duffy" charles@dyfis.net wrote:

Howdy, all --

I have a ruby_block in which I do some comparison of file mtimes at
execution time, and -- depending on the result -- may or may not wish to
trigger a delayed action.

Thing is... what's the syntax to do so? This is in Chef 0.10, and the
targeted resource hasn't been declared yet at the time (so the old-style
references, as I understand it, aren't yet available).

Thanks!