Skip to content
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

Merged
merged 10 commits into from Oct 19, 2017

Conversation

adamruzicka
Copy link
Contributor

to allow easy toggle of the cleanup, so far opt-in. For discussion see theforeman/foreman-tasks#247

@theforeman-bot
Copy link
Member

@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 git commit --amend).


This message was auto-generated by Foreman's prprocessor

@theforeman-bot
Copy link
Member

@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 git commit --amend).


This message was auto-generated by Foreman's prprocessor

Copy link
Member

@ekohl ekohl left a 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.

@@ -20,4 +23,22 @@
enable => true,
name => $service,
}
$cron_content = @(END)
Copy link
Member

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').

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 {
Copy link
Member

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.

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,
Copy link
Member

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.

@theforeman-bot
Copy link
Member

@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 git commit --amend).


This message was auto-generated by Foreman's prprocessor

@theforeman-bot
Copy link
Member

@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 git commit --amend).


This message was auto-generated by Foreman's prprocessor

1 similar comment
@theforeman-bot
Copy link
Member

@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 git commit --amend).


This message was auto-generated by Foreman's prprocessor

@adamruzicka
Copy link
Contributor Author

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.

Copy link
Member

@ekohl ekohl left a 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.

@@ -20,4 +23,15 @@
enable => true,
name => $service,
}
$cron_state = if $automatic_cleanup {
Copy link
Member

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',
}

file { 'foreman-tasks-cleanup-cron':
ensure => $cron_state,
owner => 'root',
path => '/etc/cron.d/foreman-tasks-cleanup',
Copy link
Member

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': }

}
file { 'foreman-tasks-cleanup-cron':
ensure => $cron_state,
owner => 'root',
Copy link
Member

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.

@theforeman-bot
Copy link
Member

@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 git commit --amend).


This message was auto-generated by Foreman's prprocessor

1 similar comment
@theforeman-bot
Copy link
Member

@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 git commit --amend).


This message was auto-generated by Foreman's prprocessor

@theforeman-bot
Copy link
Member

@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 git commit --amend).


This message was auto-generated by Foreman's prprocessor

@adamruzicka adamruzicka changed the title Fixes #16922 - Allow turning task cleanup cron on and off Fixes # - Allow turning task cleanup cron on and off Aug 31, 2017
@adamruzicka adamruzicka changed the title Fixes # - Allow turning task cleanup cron on and off Fixes #20819 - Allow turning task cleanup cron on and off Aug 31, 2017
ensure => $cron_state,
owner => 'root',
group => 'root',
mode => 'u=rw,go=r',
Copy link
Member

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.

owner => 'root',
group => 'root',
mode => 'u=rw,go=r',
path => '/etc/cron.d/foreman-tasks',
Copy link
Member

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
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

(done)

Copy link
Member

@ekohl ekohl left a 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
Copy link
Member

Choose a reason for hiding this comment

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

(done)

@adamruzicka
Copy link
Contributor Author

Still pending the tasks PR

@ekohl
Copy link
Member

ekohl commented Sep 6, 2017

Ok, added the label Waiting on contributor for now.

@ehelms
Copy link
Member

ehelms commented Oct 13, 2017

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.

@adamruzicka
Copy link
Contributor Author

Converted the cron file to a template, hope having the entire cronline as a single string is enough.

FOREMAN_HOME=/usr/share/foreman

# Clean up expired tasks from the database
<% cronline = scope.lookupvar("::foreman::plugin::tasks::cron_line") %>
Copy link
Member

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.

Copy link
Contributor Author

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...

@@ -1,5 +1,7 @@
# Data for the foreman-tasks plugin
class foreman::plugin::tasks::params {
$automatic_cleanup = false
$cron_line = "45 19 * * *"
Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

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

Updated

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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@ehelms
Copy link
Member

ehelms commented Oct 19, 2017

Templating and configuration aspect look good, thanks @adamruzicka for making that change

@mmoll mmoll merged commit 56d196b into theforeman:master Oct 19, 2017
@mmoll
Copy link
Contributor

mmoll commented Oct 19, 2017

merged, díky @adamruzicka!

@adamruzicka adamruzicka deleted the cron-tasks-cleanup branch October 19, 2017 17:19
@adamruzicka
Copy link
Contributor Author

Thanks everybody who helped me pull this one through

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants