Add sleep in cache cron jobs
... so that users can avoid executing the same cron command at the same
time in multiple nodes.
Technically this can be done without this change by setting a different
cron job schedule in each node but it requires complicated parameter
setting.
Change-Id: I596879d5d46f23e54fe344d5bf93a57837a6d287
(cherry picked from commit 21c95657ef
)
This commit is contained in:
parent
e6b62ff267
commit
62ad4d6a7c
|
@ -20,9 +20,15 @@
|
|||
# (optional) Defaults to '*'.
|
||||
#
|
||||
# [*command_options*]
|
||||
# command options to add to the cronjob
|
||||
# (optional) command options to add to the cronjob
|
||||
# (eg. point to config file, or redirect output)
|
||||
# (optional) Defaults to ''.
|
||||
# Defaults to ''.
|
||||
#
|
||||
# [*maxdelay*]
|
||||
# (optional) In Seconds. Should be a positive integer.
|
||||
# Induces a random delay before running the cronjob to avoid running
|
||||
# all cron jobs at the same time on all hosts this job is configured.
|
||||
# Defaults to 0.
|
||||
#
|
||||
class glance::cache::cleaner(
|
||||
$minute = 1,
|
||||
|
@ -31,13 +37,20 @@ class glance::cache::cleaner(
|
|||
$month = '*',
|
||||
$weekday = '*',
|
||||
$command_options = '',
|
||||
$maxdelay = 0
|
||||
) {
|
||||
|
||||
include glance::deps
|
||||
include glance::params
|
||||
|
||||
if $maxdelay == 0 {
|
||||
$sleep = ''
|
||||
} else {
|
||||
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
||||
}
|
||||
|
||||
cron { 'glance-cache-cleaner':
|
||||
command => "${glance::params::cache_cleaner_command} ${command_options}",
|
||||
command => "${sleep}${glance::params::cache_cleaner_command} ${command_options}",
|
||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
user => $::glance::params::user,
|
||||
minute => $minute,
|
||||
|
|
|
@ -20,9 +20,15 @@
|
|||
# (optional) Defaults to '*'.
|
||||
#
|
||||
# [*command_options*]
|
||||
# command options to add to the cronjob
|
||||
# (optional) command options to add to the cronjob
|
||||
# (eg. point to config file, or redirect output)
|
||||
# (optional) Defaults to ''.
|
||||
# Defaults to ''.
|
||||
#
|
||||
# [*maxdelay*]
|
||||
# (optional) In Seconds. Should be a positive integer.
|
||||
# Induces a random delay before running the cronjob to avoid running
|
||||
# all cron jobs at the same time on all hosts this job is configured.
|
||||
# Defaults to 0.
|
||||
#
|
||||
class glance::cache::pruner(
|
||||
$minute = '*/30',
|
||||
|
@ -31,13 +37,20 @@ class glance::cache::pruner(
|
|||
$month = '*',
|
||||
$weekday = '*',
|
||||
$command_options = '',
|
||||
$maxdelay = 0
|
||||
) {
|
||||
|
||||
include glance::deps
|
||||
include glance::params
|
||||
|
||||
if $maxdelay == 0 {
|
||||
$sleep = ''
|
||||
} else {
|
||||
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
||||
}
|
||||
|
||||
cron { 'glance-cache-pruner':
|
||||
command => "${glance::params::cache_pruner_command} ${command_options}",
|
||||
command => "${sleep}${glance::params::cache_pruner_command} ${command_options}",
|
||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
user => $::glance::params::user,
|
||||
minute => $minute,
|
||||
|
@ -46,6 +59,5 @@ class glance::cache::pruner(
|
|||
month => $month,
|
||||
weekday => $weekday,
|
||||
require => Anchor['glance::config::end'],
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
The ``glance::cache::cleaner`` class and the ``glance::cache::pruner``
|
||||
class now support the ``maxdelay`` parameter. This parameter would be
|
||||
useful in a multi-node deployment, to avoid launching the same cron command
|
||||
at the same time in multiple nodes.
|
|
@ -33,11 +33,12 @@ describe 'glance::cache::cleaner' do
|
|||
:month => '2',
|
||||
:weekday => '3',
|
||||
:command_options => '--config-dir /etc/glance/',
|
||||
:maxdelay => 3600,
|
||||
}
|
||||
end
|
||||
it 'configures a cron' do
|
||||
is_expected.to contain_cron('glance-cache-cleaner').with(
|
||||
:command => 'glance-cache-cleaner --config-dir /etc/glance/',
|
||||
:command => 'sleep `expr ${RANDOM} \\% 3600`; glance-cache-cleaner --config-dir /etc/glance/',
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
:user => 'glance',
|
||||
:minute => 59,
|
||||
|
|
|
@ -32,11 +32,12 @@ describe 'glance::cache::pruner' do
|
|||
:month => '2',
|
||||
:weekday => '3',
|
||||
:command_options => '--config-dir /etc/glance/',
|
||||
:maxdelay => 3600,
|
||||
}
|
||||
end
|
||||
it 'configures a cron' do
|
||||
is_expected.to contain_cron('glance-cache-pruner').with(
|
||||
:command => 'glance-cache-pruner --config-dir /etc/glance/',
|
||||
:command => 'sleep `expr ${RANDOM} \\% 3600`; glance-cache-pruner --config-dir /etc/glance/',
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
:user => 'glance',
|
||||
:minute => 59,
|
||||
|
|
Loading…
Reference in New Issue