From 2174ea7e9aa313154a2e47e82c24b2b01e402ebf Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Tue, 5 Oct 2021 15:26:53 +0200 Subject: [PATCH] Use shared_resources in dispatch calls fixes #9489 --- CHANGES/9489.feature | 1 + pulp_ansible/app/viewsets.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 CHANGES/9489.feature diff --git a/CHANGES/9489.feature b/CHANGES/9489.feature new file mode 100644 index 000000000..5e013de5d --- /dev/null +++ b/CHANGES/9489.feature @@ -0,0 +1 @@ +Use ``shared_resources`` in tasks where appropriate. diff --git a/pulp_ansible/app/viewsets.py b/pulp_ansible/app/viewsets.py index 872ae241a..c1d8e0c11 100644 --- a/pulp_ansible/app/viewsets.py +++ b/pulp_ansible/app/viewsets.py @@ -267,7 +267,8 @@ def sync(self, request, pk): result = dispatch( sync_func, - exclusive_resources=[repository, remote], + exclusive_resources=[repository], + shared_resources=[remote], kwargs=sync_kwargs, ) return OperationPostponedResponse(result, request) @@ -399,9 +400,14 @@ def create(self, request): config = serializer.validated_data["config"] - config, repos = self._process_config(config) + config, exclusive_resources, shared_resources = self._process_config(config) - async_result = dispatch(copy_content, exclusive_resources=repos, args=[config], kwargs={}) + async_result = dispatch( + copy_content, + exclusive_resources=exclusive_resources, + shared_resources=shared_resources, + args=[config], + ) return OperationPostponedResponse(async_result, request) def _process_config(self, config): @@ -412,7 +418,8 @@ def _process_config(self, config): repos so that the task can lock on them. """ result = [] - repos = [] + exclusive_resources = [] + shared_resources = [] for entry in config: r = dict() @@ -422,7 +429,8 @@ def _process_config(self, config): dest_repo = NamedModelViewSet().get_resource(entry["dest_repo"], AnsibleRepository) r["source_repo_version"] = source_version.pk r["dest_repo"] = dest_repo.pk - repos.extend((source_version.repository, dest_repo)) + exclusive_resources.append(dest_repo) + shared_resources.append(source_version.repository) if "dest_base_version" in entry: try: @@ -441,4 +449,4 @@ def _process_config(self, config): r["content"].append(NamedModelViewSet().extract_pk(c)) result.append(r) - return result, repos + return result, exclusive_resources, shared_resources