Skip to content

Commit

Permalink
ACS refresh
Browse files Browse the repository at this point in the history
adding ACS refresh endpoing using TaskGroupResponse

closes: #9377
https://pulp.plan.io/issues/9377
  • Loading branch information
pavelpicka committed Sep 13, 2021
1 parent e6cc190 commit d458e12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 66 deletions.
3 changes: 0 additions & 3 deletions pulp_file/app/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
from .publishing import publish # noqa
from .synchronizing import synchronize # noqa

# file_acs_refresh must be imported after synchronize to avoid circular import
from .acs import file_acs_refresh # noqa
55 changes: 0 additions & 55 deletions pulp_file/app/tasks/acs.py

This file was deleted.

52 changes: 44 additions & 8 deletions pulp_file/app/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import os

from django_filters import CharFilter
from drf_spectacular.utils import extend_schema
from rest_framework.decorators import action

from pulpcore.plugin.actions import ModifyRepositoryActionMixin
from pulpcore.plugin.models import (
AlternateContentSource,
AlternateContentSourcePath,
CreatedResource,
TaskGroup,
)
from pulpcore.plugin.serializers import (
AsyncOperationResponseSerializer,
RepositorySyncURLSerializer,
Expand All @@ -18,6 +26,7 @@
RepositoryViewSet,
RepositoryVersionViewSet,
SingleArtifactContentUploadViewSet,
TaskGroupResponse,
)

from . import tasks
Expand Down Expand Up @@ -204,12 +213,39 @@ def refresh(self, request, pk):
"""
Refresh ACS metadata.
"""
acs = self.get_object()
result = dispatch(
tasks.file_acs_refresh,
[acs],
kwargs={
"acs_pk": pk,
},
acs = AlternateContentSource.objects.get(pk=pk)
acs_paths = AlternateContentSourcePath.objects.filter(alternate_content_source=pk)
task_group = TaskGroup.objects.create(
description=f"Refreshing {acs_paths.count()} alternate content source paths."
)
return OperationPostponedResponse(result, request)

for acs_path in acs_paths:
# Create or get repository for the path
repo_data = {
"name": f"{acs.name}--{acs_path.pk}--repository",
"retain_repo_versions": 1,
"user_hidden": True,
}
repo, created = FileRepository.objects.get_or_create(**repo_data)
if created:
acs_path.repository = repo
acs_path.save()
acs_url = os.path.join(acs.remote.url, acs_path.path)

# Dispatching ACS path to own task and assign it to common TaskGroup
task = dispatch(
tasks.synchronize,
shared_resources=[acs.remote],
exclusive_resources=[acs],
task_group=task_group,
kwargs={
"remote_pk": str(acs.remote.pk),
"repository_pk": str(acs_path.repository.pk),
"mirror": False,
"url": acs_url,
},
)
CreatedResource(content_object=task) # No effect on http responses
CreatedResource(content_object=task_group) # No effect on http responses

return TaskGroupResponse(task_group, request)

0 comments on commit d458e12

Please sign in to comment.