Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Return a single task for task operations #3442

Merged
merged 1 commit into from Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis/install.sh
Expand Up @@ -28,7 +28,7 @@ fi
if [ -z $PULP_SMASH_PR_NUMBER ]; then
pip install git+https://github.com/PulpQE/pulp-smash.git#egg=pulp-smash
else
export PULP_SMASH_SHA=$(http https://api.github.com/repos/PulpQE/pulp-smash/pulls/$PULP_SMASH_PR_NUMBER | jq -r '.merge_commit_sha')
export PULP_SMASH_SHA=$(curl https://api.github.com/repos/PulpQE/pulp-smash/pulls/$PULP_SMASH_PR_NUMBER | jq -r '.merge_commit_sha')
cd ../
git clone https://github.com/PulpQE/pulp-smash.git
cd pulp-smash
Expand Down
31 changes: 11 additions & 20 deletions pulpcore/pulpcore/app/response.py
Expand Up @@ -4,34 +4,25 @@

class OperationPostponedResponse(Response):
"""
An HTTP response class for returning 202 and a list of spawned tasks.
An HTTP response class for returning 202 and a spawned task.

This response object should be used by views that dispatch asynchronous tasks. The most common
use case is for sync and publish operations. When JSON is requested, the response will look
like the following::

[
{
"_href": "https://example.com/api/v3/tasks/adlfk-bala-23k5l7-lslser",
"task_id": "adlfk-bala-23k5l7-lslser"
},
{
"_href": "https://example.com/api/v3/tasks/fr63x-dlsd-4566g-dv64m",
"task_id": "fr63x-dlsd-4566g-dv64m"
}
]
{
"_href": "https://example.com/api/v3/tasks/adlfk-bala-23k5l7-lslser",
"task_id": "adlfk-bala-23k5l7-lslser"
}
"""

def __init__(self, task_results, request):
def __init__(self, result, request):
"""
Args:
task_results (list): List of :class:`celery.result.AsyncResult` objects used to
generate the response.
task_result (pulpcore.app.models.Task): A :class:`celery.result.AsyncResult` object used
to generate the response.
request (rest_framework.request.Request): Request used to generate the _href urls
"""
tasks = []
for result in task_results:
task = {"_href": reverse('tasks-detail', args=[result.task_id], request=request),
"task_id": result.task_id}
tasks.append(task)
super().__init__(data=tasks, status=202)
task = {"_href": reverse('tasks-detail', args=[result.task_id], request=request),
"task_id": result.task_id}
super().__init__(data=task, status=202)
2 changes: 1 addition & 1 deletion pulpcore/pulpcore/app/views/orphans.py
Expand Up @@ -12,4 +12,4 @@ def delete(self, request, format=None):
"""
async_result = orphan_cleanup.apply_async_with_reservation([])

return OperationPostponedResponse([async_result], request)
return OperationPostponedResponse(async_result, request)
4 changes: 2 additions & 2 deletions pulpcore/pulpcore/app/viewsets/base.py
Expand Up @@ -292,7 +292,7 @@ def update(self, request, pk, **kwargs):
[instance], args=(pk, app_label, serializer.__class__.__name__),
kwargs={'data': request.data, 'partial': partial}
)
return OperationPostponedResponse([async_result], request)
return OperationPostponedResponse(async_result, request)

def partial_update(self, request, *args, **kwargs):
kwargs['partial'] = True
Expand All @@ -315,4 +315,4 @@ def destroy(self, request, pk, **kwargs):
[instance],
args=(pk, app_label, serializer.__class__.__name__)
)
return OperationPostponedResponse([async_result], request)
return OperationPostponedResponse(async_result, request)
8 changes: 4 additions & 4 deletions pulpcore/pulpcore/app/viewsets/repository.py
Expand Up @@ -66,7 +66,7 @@ def update(self, request, pk, partial=False):
args=(instance.id, ),
kwargs={'data': request.data, 'partial': partial}
)
return OperationPostponedResponse([async_result], request)
return OperationPostponedResponse(async_result, request)

def destroy(self, request, pk):
"""
Expand All @@ -75,7 +75,7 @@ def destroy(self, request, pk):
repo = self.get_object()
async_result = tasks.repository.delete.apply_async_with_reservation(
[repo], kwargs={'repo_id': repo.id})
return OperationPostponedResponse([async_result], request)
return OperationPostponedResponse(async_result, request)


class RepositoryVersionContentFilter(Filter):
Expand Down Expand Up @@ -220,7 +220,7 @@ def destroy(self, request, repository_pk, number):
async_result = tasks.repository.delete_version.apply_async_with_reservation(
[version.repository], kwargs={'pk': version.pk}
)
return OperationPostponedResponse([async_result], request)
return OperationPostponedResponse(async_result, request)

def create(self, request, repository_pk):
"""
Expand Down Expand Up @@ -248,7 +248,7 @@ def create(self, request, repository_pk):
'remove_content_units': remove_content_units
}
)
return OperationPostponedResponse([result], request)
return OperationPostponedResponse(result, request)


class RemoteFilter(filterset.FilterSet):
Expand Down