New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #20819 - Allow turning task cleanup cron on and off #582
Conversation
@adamruzicka, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
@adamruzicka, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to revisit #484 and determine the automatic_cleanup
on the config value cleanup_after
.
manifests/plugin/tasks.pp
Outdated
@@ -20,4 +23,22 @@ | |||
enable => true, | |||
name => $service, | |||
} | |||
$cron_content = @(END) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's cleaner to move this to files/tasks.cron
and use content => file('foreman/tasks.cron')
.
manifests/plugin/tasks.pp
Outdated
45 19 * * * foreman /usr/sbin/foreman-rake foreman_tasks:cleanup >>/var/log/foreman/cron.log 2>&1 | ||
| END | ||
file { 'foreman-tasks-cleanup-cron': | ||
ensure => if $automatic_cleanup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline conditional is not that readable so I'd prefer a separate variable.
manifests/plugin/tasks.pp
Outdated
class foreman::plugin::tasks( | ||
String $package = $::foreman::plugin::tasks::params::package, | ||
String $service = $::foreman::plugin::tasks::params::service, | ||
String $package = $::foreman::plugin::tasks::params::package, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't align parameters anymore. Too much changes, huge diffs for little benefit.
@adamruzicka, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
@adamruzicka, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
1 similar comment
@adamruzicka, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
I'm not against revisiting the other foreman-tasks PR, but we would probably still keep this on/off option for the cleaner, because of changes in the cleaner itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against a parameter.
manifests/plugin/tasks.pp
Outdated
@@ -20,4 +23,15 @@ | |||
enable => true, | |||
name => $service, | |||
} | |||
$cron_state = if $automatic_cleanup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following syntax is a bit more common:
$cron_state = $automatic_cleanup ? {
true => 'present',
default => 'absent',
}
manifests/plugin/tasks.pp
Outdated
file { 'foreman-tasks-cleanup-cron': | ||
ensure => $cron_state, | ||
owner => 'root', | ||
path => '/etc/cron.d/foreman-tasks-cleanup', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would foreman-tasks
be more future proof? There could be another cronjob. We also often put the path in the file resource: file { '/etc/cron.d/foreman-tasks': }
manifests/plugin/tasks.pp
Outdated
} | ||
file { 'foreman-tasks-cleanup-cron': | ||
ensure => $cron_state, | ||
owner => 'root', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add the group => 'root'
as well? Otherwise Puppet will try to derive it based on the file owner of the manifest which could be different. An explicit mode might be a good idea as well.
@adamruzicka, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
1 similar comment
@adamruzicka, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
@adamruzicka, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:
If changing the ticket number used, remember to update the PR title and the commit message (using This message was auto-generated by Foreman's prprocessor |
4e09b6f
to
9d08f3a
Compare
manifests/plugin/tasks.pp
Outdated
ensure => $cron_state, | ||
owner => 'root', | ||
group => 'root', | ||
mode => 'u=rw,go=r', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we write 0644 but this works too I believe.
manifests/plugin/tasks.pp
Outdated
owner => 'root', | ||
group => 'root', | ||
mode => 'u=rw,go=r', | ||
path => '/etc/cron.d/foreman-tasks', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now redundant since you have it in the title.
files/tasks.cron
Outdated
FOREMAN_HOME=/usr/share/foreman | ||
|
||
# Clean up expired tasks from the database | ||
45 19 * * * foreman /usr/sbin/foreman-rake foreman_tasks:cleanup >>/var/log/foreman/cron.log 2>&1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we have line endings at the end of the file, this results in smaller diffs if you add another line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(done)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still pending the tasks pr or is this already something that is useful?
files/tasks.cron
Outdated
FOREMAN_HOME=/usr/share/foreman | ||
|
||
# Clean up expired tasks from the database | ||
45 19 * * * foreman /usr/sbin/foreman-rake foreman_tasks:cleanup >>/var/log/foreman/cron.log 2>&1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(done)
Still pending the tasks PR |
Ok, added the label Waiting on contributor for now. |
I anticipate we are going to get requests to be able to customize the cron timestamp. While users could hand edit it, the moment they run the installer again this would get wiped out. I'd recommend solving this now rather than later by introducing a variable and templatizing the cron. |
Converted the cron file to a template, hope having the entire cronline as a single string is enough. |
templates/tasks.cron.erb
Outdated
FOREMAN_HOME=/usr/share/foreman | ||
|
||
# Clean up expired tasks from the database | ||
<% cronline = scope.lookupvar("::foreman::plugin::tasks::cron_line") %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cronline is in the local scope so @cronline
also works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chmm, the tests don't seem to like this change
pebcak...
manifests/plugin/tasks/params.pp
Outdated
@@ -1,5 +1,7 @@ | |||
# Data for the foreman-tasks plugin | |||
class foreman::plugin::tasks::params { | |||
$automatic_cleanup = false | |||
$cron_line = "45 19 * * *" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
manifests/plugin/tasks/params.pp:4:WARNING: double quoted string containing no variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
templates/tasks.cron.erb
Outdated
FOREMAN_HOME=/usr/share/foreman | ||
|
||
# Clean up expired tasks from the database | ||
<%= @cron_line %> foreman /usr/sbin/foreman-rake foreman_tasks:cleanup >>/var/log/foreman/cron.log 2>&1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The foreman username is also available as the variable foreman::user
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Templating and configuration aspect look good, thanks @adamruzicka for making that change |
merged, díky @adamruzicka! |
Thanks everybody who helped me pull this one through |
to allow easy toggle of the cleanup, so far opt-in. For discussion see theforeman/foreman-tasks#247