Adds OperationPostponedResponse object #2815
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
| :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} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 What do others think about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is placeholder code, what about replacing this with |
||
| tasks.append(task) | ||
| super(OperationPostponedResponse, self).__init__(data=tasks, status=202) | ||
This file was deleted.
There was a problem hiding this comment.
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?