Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Add support for multiple cron agent runs per hour #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$gentoo_keywords = $puppet::params::agent_keywords,
$manage_package = true,
$stringify_facts = $puppet::server::stringify_facts,
$frequency = 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this to $cron_frequency please? (only here, not in puppet::agent::cron)

) inherits puppet::params {

include puppet
Expand All @@ -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
Expand Down
11 changes: 8 additions & 3 deletions manifests/agent/cron.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class puppet::agent::cron (
$enable = true,
$run_noop = false,
$enable = true,
$run_noop = false,
$frequency = 1
) {
include puppet::params

Expand All @@ -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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm, does this mean it's puppet 4 only code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igalic correct, future-parser only. I'm no longer running current parser anywhere so I have no personal need for backwards compatibility, but I wanted to get feedback before going further because I realize that not everybody is ready to make the switch.

If requiring future parser isn't feasible for other puppet-puppet users, I think the second-best option would be to simply parameterize puppet::agent to accept a field passed directly to the minute parameter on the cron resource, defaulting to fqdn_rand(60), and leaving a comment / documentation to suggest adding code like this future-parser-only material in the profile that wraps puppet-puppet for people who want to use it.

If future-parser-only code would cause problems for you, I'm totally fine solving this another way -- I just wanted to propose what I see as the most elegant fix first, in case others are fine with future parser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gosh, i really want to switch.
i wonder how many of the modules i use would cough up blood the moment i do…


cron { 'puppet agent':
ensure => $ensure,
command => $cmd,
minute => fqdn_rand(60),
minute => $cron_schedule,
}
}
3 changes: 2 additions & 1 deletion tests/agent_cron.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class { 'puppet::agent':
method => 'cron',
method => 'cron',
frequency => 2,
}