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
This commit is contained in:
parent
daa8abd50a
commit
21c95657ef
|
@ -20,9 +20,15 @@
|
||||||
# (optional) Defaults to '*'.
|
# (optional) Defaults to '*'.
|
||||||
#
|
#
|
||||||
# [*command_options*]
|
# [*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)
|
# (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(
|
class glance::cache::cleaner(
|
||||||
$minute = 1,
|
$minute = 1,
|
||||||
|
@ -31,13 +37,20 @@ class glance::cache::cleaner(
|
||||||
$month = '*',
|
$month = '*',
|
||||||
$weekday = '*',
|
$weekday = '*',
|
||||||
$command_options = '',
|
$command_options = '',
|
||||||
|
$maxdelay = 0
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include glance::deps
|
include glance::deps
|
||||||
include glance::params
|
include glance::params
|
||||||
|
|
||||||
|
if $maxdelay == 0 {
|
||||||
|
$sleep = ''
|
||||||
|
} else {
|
||||||
|
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
||||||
|
}
|
||||||
|
|
||||||
cron { 'glance-cache-cleaner':
|
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',
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
user => $::glance::params::user,
|
user => $::glance::params::user,
|
||||||
minute => $minute,
|
minute => $minute,
|
||||||
|
|
|
@ -20,9 +20,15 @@
|
||||||
# (optional) Defaults to '*'.
|
# (optional) Defaults to '*'.
|
||||||
#
|
#
|
||||||
# [*command_options*]
|
# [*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)
|
# (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(
|
class glance::cache::pruner(
|
||||||
$minute = '*/30',
|
$minute = '*/30',
|
||||||
|
@ -31,13 +37,20 @@ class glance::cache::pruner(
|
||||||
$month = '*',
|
$month = '*',
|
||||||
$weekday = '*',
|
$weekday = '*',
|
||||||
$command_options = '',
|
$command_options = '',
|
||||||
|
$maxdelay = 0
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include glance::deps
|
include glance::deps
|
||||||
include glance::params
|
include glance::params
|
||||||
|
|
||||||
|
if $maxdelay == 0 {
|
||||||
|
$sleep = ''
|
||||||
|
} else {
|
||||||
|
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
||||||
|
}
|
||||||
|
|
||||||
cron { 'glance-cache-pruner':
|
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',
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
user => $::glance::params::user,
|
user => $::glance::params::user,
|
||||||
minute => $minute,
|
minute => $minute,
|
||||||
|
@ -46,6 +59,5 @@ class glance::cache::pruner(
|
||||||
month => $month,
|
month => $month,
|
||||||
weekday => $weekday,
|
weekday => $weekday,
|
||||||
require => Anchor['glance::config::end'],
|
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',
|
:month => '2',
|
||||||
:weekday => '3',
|
:weekday => '3',
|
||||||
:command_options => '--config-dir /etc/glance/',
|
:command_options => '--config-dir /etc/glance/',
|
||||||
|
:maxdelay => 3600,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
it 'configures a cron' do
|
it 'configures a cron' do
|
||||||
is_expected.to contain_cron('glance-cache-cleaner').with(
|
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',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
:user => 'glance',
|
:user => 'glance',
|
||||||
:minute => 59,
|
:minute => 59,
|
||||||
|
|
|
@ -32,11 +32,12 @@ describe 'glance::cache::pruner' do
|
||||||
:month => '2',
|
:month => '2',
|
||||||
:weekday => '3',
|
:weekday => '3',
|
||||||
:command_options => '--config-dir /etc/glance/',
|
:command_options => '--config-dir /etc/glance/',
|
||||||
|
:maxdelay => 3600,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
it 'configures a cron' do
|
it 'configures a cron' do
|
||||||
is_expected.to contain_cron('glance-cache-pruner').with(
|
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',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
:user => 'glance',
|
:user => 'glance',
|
||||||
:minute => 59,
|
:minute => 59,
|
||||||
|
|
Loading…
Reference in New Issue