The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

This issue tracker is now in read-only archive mode and automatic ticket export has been disabled. Redmine users will need to create a new JIRA account to file tickets using https://tickets.puppetlabs.com. See the following page for information on filing tickets with JIRA:

Feature #311

cron random time

Added by ghislain - over 9 years ago. Updated almost 8 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Puppet Community% Done:

0%

Category:cron
Target version:0.24.5
Affected Puppet version:0.25.4 Branch:
Keywords:

We've Moved!

Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com


Description

hello,

could be great if the cron type could generate a radom time. So for exemple a cron on 10000 hosts would not be executed at the same time.Something like :

minutes => random

or even more power

minutes => random[10-45] // limit the random to the 10-45 minutes

perhaps this could be a function of puppet in general that could be used anywhere even in other types ?

regards, Ghislain.

fqdn_rand.patch Magnifier (766 Bytes) ben potts, 05/21/2008 08:31 pm

History

#1 Updated by Ben - almost 9 years ago

For some time i have used this method of achieving this and now i use it when setting up cron job with puppet.

cron { "Example_cron":
        command     => 'sleep $((RANDOM\%300)) ; /path/to/command',
        minute      => 20,
        user        => root
}

This example executes “/path/to/command” at a random second between 0-300 seconds (5 mins).

#2 Updated by over 9 years ago

How about seeding the RNG with the host ID (not sure if this is the correct terminology, sorry)? That way it would be different for every host but consistent and reproducible on each one.

#3 Updated by James Turnbull almost 8 years ago

  • Status changed from 1 to Closed
  • 7 set to fixed

Pushed in commit commit:d54338f8921b4b2973dcde52576d7e9fa58148cb in branch 0.24.x

#4 Updated by ben potts almost 8 years ago

Here’s a simple patch for 0.24.4 that adds a fqdn_rand() function to parser/functions.rb.

The function returns a pseudorandom integer based on the FQDN. The first argument determines the max. The second argument is optional and when used, is added to the seed generated from the fqdn.

#5 Updated by Matt Palmer over 9 years ago

I like this idea. The only dangerous bit is that if the ‘random’ fires every time, you end up with your cron jobs wandering all over the place. If that weren’t a problem, a simple random() function would do the job. As it stands, I think it’ll have to be something Cron-specific, which will only generate a new random number if it’s a new job that’s being created. I’m sure that just specifying ‘random’ would be simple to support, but I don’t know if the ranged version would be quite so easy.

Not volunteering, by the way, just commenting… (grin)

Also available in: Atom PDF