Skip to content

Commit

Permalink
Make filesystem exporter apis async
Browse files Browse the repository at this point in the history
This will introduce a change that is about to come with pulpcore 3.12
anyway. But that would introduce incompatible bindings changes between
two pulp_file releases. We must be proactive here in order to be able
to ship compatible binding packages.

Required PR: pulp/pulpcore#1200

fixes #8451
https://pulp.plan.io/issues/8451
  • Loading branch information
mdellweg authored and daviddavis committed Mar 29, 2021
1 parent 63cc411 commit 8d0a227
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/8451.bugfix
@@ -0,0 +1 @@
Added asynchronous tasking to the Update and Delete endpoints of FilesystemExporter to provide proper locking on resources.
1 change: 1 addition & 0 deletions CHANGES/8451.removal
@@ -0,0 +1 @@
Update and Delete endpoints of FilesystemExporter changed to return 202 with tasks.
55 changes: 55 additions & 0 deletions pulp_file/app/viewsets.py
Expand Up @@ -22,6 +22,7 @@
RepositoryVersionViewSet,
SingleArtifactContentUploadViewSet,
)
from pulpcore.plugin.viewsets.content import tasks as coretasks

from . import tasks
from .models import (
Expand Down Expand Up @@ -194,6 +195,60 @@ class FileFilesystemExporterViewSet(ExporterViewSet):
queryset = FileFilesystemExporter.objects.all()
serializer_class = FileFilesystemExporterSerializer

# ----8<----8<----8<----
# This section can be savely removed, once the plugin depends on pulpcore >= 3.12
@extend_schema(
description="Trigger an asynchronous update task",
responses={202: AsyncOperationResponseSerializer},
)
def update(self, request, pk, **kwargs):
"""
Update a model instance.
"""
partial = kwargs.pop("partial", False)
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
app_label = instance._meta.app_label
async_result = enqueue_with_reservation(
coretasks.base.general_update,
[instance],
args=(pk, app_label, serializer.__class__.__name__),
kwargs={"data": request.data, "partial": partial},
)
return OperationPostponedResponse(async_result, request)

@extend_schema(
description="Trigger an asynchronous partial update task",
responses={202: AsyncOperationResponseSerializer},
)
def partial_update(self, request, *args, **kwargs):
"""
Partially update a model instance.
"""
kwargs["partial"] = True
return self.update(request, *args, **kwargs)

@extend_schema(
description="Trigger an asynchronous delete task",
responses={202: AsyncOperationResponseSerializer},
)
def destroy(self, request, pk, **kwargs):
"""
Delete a model instance.
"""
instance = self.get_object()
serializer = self.get_serializer(instance)
app_label = instance._meta.app_label
async_result = enqueue_with_reservation(
coretasks.base.general_delete,
[instance],
args=(pk, app_label, serializer.__class__.__name__),
)
return OperationPostponedResponse(async_result, request)

# ----8<----8<----8<----


class FileFilesystemExportViewSet(ExportViewSet):
"""
Expand Down

0 comments on commit 8d0a227

Please sign in to comment.