Skip to content

Commit

Permalink
Use shared_resources in dispatch calls
Browse files Browse the repository at this point in the history
fixes #9489
  • Loading branch information
mdellweg committed Oct 7, 2021
1 parent 133fe87 commit 2174ea7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/9489.feature
@@ -0,0 +1 @@
Use ``shared_resources`` in tasks where appropriate.
20 changes: 14 additions & 6 deletions pulp_ansible/app/viewsets.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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

0 comments on commit 2174ea7

Please sign in to comment.