Skip to content

Commit

Permalink
Fixes #13566 - Added TaskGroup support for errata regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
parthaa committed May 25, 2016
1 parent 28cb3ef commit f803b18
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
76 changes: 76 additions & 0 deletions app/lib/actions/pulp/abstract_async_task_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module Actions
module Pulp
class AbstractAsyncTaskGroup < Pulp::Abstract
include Actions::Base::Polling

# A call report (documented https://github.com/pulp/pulp/blob/master/docs/dev-guide/integration/rest-api/consumer/applicability.rst#id65)
# Looks like:
# {
# "_href": "/pulp/api/v2/task_groups/7744e2df-39b9-46f0-bb10-feffa2f7014b/",
# "group_id": "7744e2df-39b9-46f0-bb10-feffa2f7014b"
# }
#
# A TaskGroup (https://github.com/pulp/pulp/blob/master/docs/dev-guide/integration/rest-api/tasks.rst#task-group-management)
# Looks like:
# {
# "accepted": 0,
# "finished": 100,
# "running": 4,
# "canceled": 0,
# "waiting": 2,
# "skipped": 0,
# "suspended": 0,
# "error": 0,
# "total": 106
# }

def run(event = nil)
# do nothing when the action is being skipped
unless event == Dynflow::Action::Skip
super
end
end

def humanized_state
case state
when :running
if self.external_task.nil?
_("initiating Pulp task")
else
_("checking Pulp task status")
end
else
super
end
end

def done?
finishing_states = ["finished", "canceled", "skipped", "suspended", "error"]
return false if (finishing_states - external_task.keys).present?
task_resource.completed?(external_task)
end

def external_task
output["pulp_task_group"]
end

private

def external_task=(external_task_data)
if external_task_data.key?("group_id")
output["pulp_task_group"] = {"group_id" => external_task_data["group_id"]}
else
output["pulp_task_group"] = {"group_id" => output["pulp_task_group"]["group_id"]}.merge(external_task_data)
end
end

def poll_external_task
task_resource.summary(output["pulp_task_group"]["group_id"])
end

def task_resource
::Katello.pulp_server.resources.task_group
end
end
end
end
4 changes: 2 additions & 2 deletions app/lib/actions/pulp/repository/regenerate_applicability.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Actions
module Pulp
module Repository
class RegenerateApplicability < Pulp::AbstractAsyncTask
class RegenerateApplicability < Pulp::AbstractAsyncTaskGroup
middleware.use Actions::Middleware::ExecuteIfContentsChanged

input_format do
Expand All @@ -10,7 +10,7 @@ class RegenerateApplicability < Pulp::AbstractAsyncTask
end

def invoke_external_task
pulp_extensions.repository.regenerate_applicability_by_ids([input[:pulp_id]])
pulp_extensions.repository.regenerate_applicability_by_ids([input[:pulp_id]], true)
end
end
end
Expand Down
5 changes: 0 additions & 5 deletions app/models/katello/glue/pulp/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,6 @@ def populate_from(repos_map)
!found.nil?
end

def generate_applicability
task = Katello.pulp_server.extensions.repository.regenerate_applicability_by_ids([self.pulp_id])
PulpTaskStatus.using_pulp_task(task)
end

def other_repos_with_same_product_and_content
Repository.where(:content_id => self.content_id).in_product(self.product).pluck(:pulp_id) - [self.pulp_id]
end
Expand Down

0 comments on commit f803b18

Please sign in to comment.