I have a promise that defines a class if it succeeds in fetching data from another system and writing that data to a local file:
"fetched_asset_data" expression => returnszero( "$(dg.asset_command) -o $(dg.asset_cache_file) data $(sys.uqhost)", "noshell" ); I would like this promise to be evaluated in two situations. The first is when the file /var/classes/force_asset_fetch is detected. A class matching the filename is created and the file is deleted. The above promise should run if that class is defined. This is an exceptional case, however, used when an admin just made a change to the asset database and wants Cfengine on that host to know about the change immediately. The main times this promise should run is basically once in a 12 hour period, or twice a day roughly. This is just based upon historical expectations for how often assets get updated in the database and is probably even more frequent than really needed, but across all of our systems it is probably a good balance. So I was thinking of adding "action => if_elapsed_12_hours" to the promise, where I have the body: body action if_elapsed_12_hours { ifelapsed => "720"; } So ultimately, I would like this promise to run if 12 hours has elapsed since it last ran (though I don't care when during the 12 hours) OR if the force_asset_fetch class is defined. I just can't figure out how to write the complete promise that combines both controlling factors. Any suggestions? UPDATE: Right before sending this, I thought of an idea as I was skimming the reference manual and remembering how Mark once explained something. I figured I'd leave the above explanation in case anyone has an easy answer to it, but "dist" classes may be the better way to go for this problem! Suppose I create a class promise called "percent_dist" and define it this way: classes: "percent_dist" dist => { "1", "99" }; On a default schedule, cf-agent runs every 5 minutes, or 288 times per day. The class random_dist_1 will be defined about 1% of the time (1/(1+99)) and the class random_dist_99 will be defined 99% of the time (99/(1+99)). So random_dist_1 would be defined about 2 to 3 times per day! My promise condition then becomes percent_dist_1|force_asset_fetch:: I could always tweak the percent_dist rlist if I want additional such classes for other purposes, e.g. { "1", "10", "89" } to get a percent_dist_10 class 10% of the time. The rlist values don't have to total 100, it's just a convenience. If someone wants to check my logic here, I'd appreciate it, but I think I've answered my own question. :) Justin -- Justin C. Lloyd Unix Infrastructure Engineer DigitalGlobe, An Imaging and Information Company This electronic communication and any attachments may contain confidential and proprietary information of DigitalGlobe, Inc. If you are not the intended recipient, or an agent or employee responsible for delivering this communication to the intended recipient, or if you have received this communication in error, please do not print, copy, retransmit, disseminate or otherwise use the information. Please indicate to the sender that you have received this communication in error, and delete the copy you received. DigitalGlobe reserves the right to monitor any electronic communication sent or received by its employees, agents or representatives. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine