From 4ee2c8727621ac69f650f32d8f03dd1dba7605f9 Mon Sep 17 00:00:00 2001 From: Daniel Dreier Date: Thu, 29 Jan 2015 16:16:18 -1000 Subject: [PATCH] Add support for multiple cron agent runs per hour Use map function from future parser to allow cron to run the agent more than once per hour. --- manifests/agent.pp | 5 ++++- manifests/agent/cron.pp | 11 ++++++++--- tests/agent_cron.pp | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/manifests/agent.pp b/manifests/agent.pp index 5d92a29..db5eab4 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -51,6 +51,7 @@ $gentoo_keywords = $puppet::params::agent_keywords, $manage_package = true, $stringify_facts = $puppet::server::stringify_facts, + $frequency = 1, ) inherits puppet::params { include puppet @@ -76,8 +77,10 @@ case $method { cron: { - include puppet::agent::cron class { 'puppet::agent::service': enable => false } + class { 'puppet::agent::cron': + frequency => $frequency + } } service: { include puppet::agent::service diff --git a/manifests/agent/cron.pp b/manifests/agent/cron.pp index b000a3c..e829177 100644 --- a/manifests/agent/cron.pp +++ b/manifests/agent/cron.pp @@ -1,6 +1,7 @@ class puppet::agent::cron ( - $enable = true, - $run_noop = false, + $enable = true, + $run_noop = false, + $frequency = 1 ) { include puppet::params @@ -16,9 +17,13 @@ $cmd = "${puppet::params::puppet_cmd} agent --confdir ${puppet::params::puppet_confdir} --onetime --no-daemonize >/dev/null" } + $interval = 60 / $frequency + $random_offset = fqdn_rand($interval) + $cron_schedule = $frequency.map |$value| { ($value * $interval) + $random_offset} + cron { 'puppet agent': ensure => $ensure, command => $cmd, - minute => fqdn_rand(60), + minute => $cron_schedule, } } diff --git a/tests/agent_cron.pp b/tests/agent_cron.pp index 35d755c..6e81b18 100644 --- a/tests/agent_cron.pp +++ b/tests/agent_cron.pp @@ -1,3 +1,4 @@ class { 'puppet::agent': - method => 'cron', + method => 'cron', + frequency => 2, }