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

Adds OperationPostponedResponse object #2815

Merged
merged 1 commit into from Nov 2, 2016
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
34 changes: 34 additions & 0 deletions app/pulp/app/response.py
@@ -0,0 +1,34 @@
from rest_framework.response import Response


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

This reponse 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": "/this/needs/to/be/updated/adlfk-bala-23k5l7-lslser",
"task_id": "adlfk-bala-23k5l7-lslser"
},
{
"_href": "/this/needs/to/be/updated/fr63x-dlsd-4566g-dv64m",
"task_id": "fr63x-dlsd-4566g-dv64m"
}
]
"""

def __init__(self, task_results):
"""
:param task_results: List of AsyncResult objects that are used to generate the response.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this docstring get the :class: additions with the full path to the celery AsyncResult object?

:type task_group_id: List of AsyncResult
"""
raise NotImplementedError
tasks = []
for result in task_results:
task = {"_href": result.task_id, "task_id": result.task_id}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having worked with the new REST API code, I might just be uninformed, but I'm surprised at the value for _href. Is there something else going on under the hood to convert the task_id into a path? Or is a plain task_id what we actually want?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @mhrivnak is right. The body of this probably needs to be formed automatically from the URI's of the corresponding tasks themselves in order to stay DRY. This will involve getting the actual pulp.app.models.Task object for each AsyncResult, but I that is OK because staying DRY is important and the number of them will be one or two for all non-group tasks.

What do others think about this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just place holder code for the URL. The viewsets for Tasks have not been completed yet, so I am not able to utilize the machinery available for generating the URLs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is placeholder code, what about replacing this with NotImplementedError and putting a requirement on the viewset for Tasks for finish it?

tasks.append(task)
super(OperationPostponedResponse, self).__init__(data=tasks, status=202)
57 changes: 0 additions & 57 deletions server/pulp/server/webservices/middleware/postponed.py

This file was deleted.