Skip to content

Commit d98b1f3

Browse files
aarthi-aximaarthi
andauthored
Include result in async task response (#494)
Includes `result` in `async` task response. Co-authored-by: aarthi <[email protected]>
1 parent 417b8c6 commit d98b1f3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

apps/async_task/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def async_download_result(request, result_id, result_is_json=False, content_type
1515
# only check if the file is ready
1616
from htk.api.utils import json_response
1717
response = json_response({
18-
'ready' : result.ready(),
18+
'ready': result.ready(),
1919
})
2020
else:
2121
# attempt to download file
@@ -42,6 +42,7 @@ def async_download_result(request, result_id, result_is_json=False, content_type
4242
response = HttpResponseAccepted()
4343
return response
4444

45+
4546
def async_task_status(request, result_id):
4647
from celery.result import AsyncResult
4748
result = AsyncResult(result_id)
@@ -51,7 +52,8 @@ def async_task_status(request, result_id):
5152
response = json_response({
5253
# possible states: PENDING | STARTED | RETRY | FAILURE | SUCCESS
5354
# see celery/result.py
54-
'state' : result.state,
55-
'ready' : result.ready(),
55+
'state': result.state,
56+
'ready': result.ready(),
57+
'result': result.result if result.successful() else None,
5658
})
5759
return response

0 commit comments

Comments
 (0)