How to cancel Pulp related foreman tasks in batch
Environment
- Red Hat Satellite 6
Issue
- Large number of Pulp related foreman tasks, such as Capsule Repository sync tasks that have been running for long time and never finish. It is painful to cancel all of them one by one in the Web UI.
Resolution
- Run the following command in the Satellite server to access the foreman console.
foreman-rake console
-
You can check if a particular foreman task is cancellable. A task is cancellable when it is in "running" state.
-
The command will return true if the task is cancellable. Running task is normally cancellable.
ForemanTasks::Task.where(label: "Actions::Katello::Repository::Sync", state: "running", result: "pending").first.cancellable? => true -
The command will return false if the task is not allowed to cancel. Paused task is not allow to cancel.
ForemanTasks::Task.where(label: "Actions::Katello::Repository::Sync", state: "paused", result: "error").first.cancellable? => false
-
-
Batch cancel multiple tasks. The command will return an array of true that matches the number of tasks which have been cancelled successfully.
-
Cancel all running Sync tasks.
ForemanTasks::Task.where(label: "Actions::Katello::Repository::Sync", state: "running", result: "pending").map(&:cancel) -
Cancel all running Sync tasks that have been running for more than a day
ForemanTasks::Task.where(label: "Actions::Katello::Repository::Sync", state: "running", result: "pending").where("started_at < ?", 1.day.ago).map(&:cancel) -
Cancel all running Capsule Sync tasks that have been running for more than a day
ForemanTasks::Task.where(label: "Actions::Katello::Repository::CapsuleGenerateAndSync", state: "running", result: "pending").where("started_at < ?", 1.day.ago).map(&:cancel) -
Cancel all Upload Package Profile tasks and Generate Applicability tasks that have been running for more than a day
ForemanTasks::Task.where(label: ["Actions::Katello::Host::UploadPackageProfile", "Actions::Katello::Host::GenerateApplicability"], state: "running", result: "pending").where("started_at < ?", 1.day.ago).map(&:cancel)
-
For more KB articles/solutions related to Red Hat Satellite 6.x Pulp 2.0 Issues, please refer to the Consolidated Troubleshooting Article for Red Hat Satellite 6.x Pulp 2.0-related Issues
Root Cause
- Pulp related foreman tasks take too long to run and never finish due to several reasons and bugs in Satellite 6.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.