First of all, make sure you have a working backup since this method is potentially destructive! I am not responsible for any data loss or broken configurations in your environment.
I've run into a situation where multiple tasks (~8.000) tasks were stuck in execution over the course of a week. Canceling them by hand will take me forever and the WebUI is non-responsive when selecting this amount of tasks, so foreman-rake to the rescue it is.
Start by finding out the label of the process you are going to stop:
[root@katello ~]# su - postgres -c "psql -d foreman -c 'select label,state,result from foreman_tasks_tasks where state = '\''running'\'' and result = '\''pending'\''';"
For me the label was 'Actions::RemoteExecution::RunHostJob'. Here're all the details I was searching for using foreman-rake:
- label: 'Actions::RemoteExecution::RunHostJob'
- state: 'running' or 'pending'
- result: 'pending'
I'll add an additional filter to that where I will only delete tasks that have been started 1 day ago:
[root@katelo ~]# foreman-rake foreman_tasks:cleanup TASK_SEARCH='label = "Actions::RemoteExecution::RunHostJob", result = pending' STATES='running,pending' AFTER='1d' VERBOSE=true
This might take a minute to complete but you can monitor the tasks matching your criteria in the WebUI their amount should decrease.
Feel free to comment and / or suggest a topic.
Comments
Post a Comment