body action if_elapsedwork with
Let's start with the details of
body action if_elapsed.
ifelapsed action body attribute is the number of minutes before next
allowed assessment of a promise. It overrides
body agent control ifelapsed
which defaults to 1 minute. It's intended to prevent overload due to
unintentional resource consumption, but it can be used to control frequency. The
expireafter action body attribute is the number of minutes a promise is
allowed to run before the agent is subject to termination.
if_elapsed action body is saying that once the promise has been
verified as having an outcome of kept or repaired it should remain locked for x
minutes. The agent should not try to re-verify it until that lock is no longer
valid. Additionally if another agent sees that an agent is still executing the
promise after x minutes then the apparently stuck agent should be terminated.
In cfengine a promise is locked once it is seen to be kept or repaired. By
default promises are locked for 1 minute. Until a lock expires the promise will
be skipped. In this example, there are two promises. One promise to report the
date, and one promise to report
Hello. The date will be different each time
the agent is run so the promise lock will not be the same between two agent runs
and thus it will not be affected by promise locking.
Here are the results of several executions of
cf-agent -f /tmp/example.cf.
vars type promises do not participate in promise locking and as such can not
be affected by the
ifelapsed action body attribute or the
Here are the results of a couple runs (
cf-agent -f /tmp/vars-are-not-locked.cf ).
R: Tue Dec 26 13:03:15 2017 R: Hello World
Another run a few seconds later:
R: Tue Dec 26 13:03:28 2017 R: Hello World
We can see that
Hello World was reported in both runs. It was only reported
because we attached
body action immediate to the reports promise. Note the
vars promise did not require
body action immediate in order for the variable
msg to hold the value