Puppet Function: ip_to_cron

Defined in:
lib/puppet/parser/functions/ip_to_cron.rb
Function type:
Ruby 3.x API

Overview

ip_to_cron()Variant[Integer[0,59], Array[Integer[0,59], Integer[0,23]]]

Provides a “random” value to cron based on the passed Integer value.

Used to avoid starting a certain cron job at the same time on all servers.

If used with no parameters, it will return a single value between 0-59 first argument is the occurrence within a timeframe, for example if you want it to run 2 times per hour the second argument is the timeframe, by default its 60 minutes, but it could also be 24 hours etc…

Pulled from: projects.puppetlabs.com/projects/puppet/wiki/Cron_Patterns/8/diff

  • Author: ohadlevy@gmail.com

  • License: None

Examples:


ip_to_cron()     - returns one value between 0..59
ip_to_cron(2)    - returns an array of two values between 0..59
ip_to_cron(2,24) - returns an array of two values between 0..23

Returns:

  • (Variant[Integer[0,59], Array[Integer[0,59], Integer[0,23]]])


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/parser/functions/ip_to_cron.rb', line 2

newfunction(:ip_to_cron, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|

  Puppet::Parser::Functions.autoloader.loadall
  Provides a "random" value to `cron` based on the passed `Integer` value.

  Used to avoid starting a certain cron job at the same time on all servers.

  If used with no parameters, it will return a single value between `0-59`
  first argument is the occurrence within a timeframe, for example if you
  want it to run `2` times per hour the second argument is the timeframe,
  by default its `60 minutes`, but it could also be `24 hours` etc...

  Pulled from: http://projects.puppetlabs.com/projects/puppet/wiki/Cron_Patterns/8/diff

    * Author: ohadlevy@gmail.com
    * License: None

  @example

    ip_to_cron()     - returns one value between 0..59
    ip_to_cron(2)    - returns an array of two values between 0..59
    ip_to_cron(2,24) - returns an array of two values between 0..23

  @return [Variant[Integer[0,59], Array[Integer[0,59], Integer[0,23]]]]
  ENDHEREDOC
  function_rand_cron([lookupvar('::ipaddress'),args[0],args[1]])
end